Created
June 16, 2011 16:07
-
-
Save topherfangio/1029586 to your computer and use it in GitHub Desktop.
Basic SC Bindings Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
editingPane: MyApp.editingPane.extend({}), | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
openView: function() { | |
var nestedStore = MyApp.store.chain(); | |
var record = nestedStore.createRecord(MyApp.MyRecord, { | |
id: -SC.Store.generateStoreKey(), | |
attr1: "something", | |
attr2: "another" | |
}); | |
MyApp.editMyRecordController.set('content', record); | |
MyApp.mainPage.get('editingPane').append(); | |
}, | |
saveContent: function() { | |
var record = MyApp.editMyRecordController.get('content'); | |
/* | |
* Do whatever you need to with the record OR better yet: | |
* call record.store.commitChanges() to have your datasource | |
* send the updates to the server. | |
*/ | |
MyApp.mainPage.get('editingPane').remove(); | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MyApp.editingPane = SC.Pane.extend({ | |
layout: { ... }, | |
childViews: 'attr1 attr2'.w(), | |
attr1: SC.TextFieldView.extend({ | |
layout: { ... }, | |
valueBinding: "MyApp.editMyRecordController.attr1" | |
}) | |
attr2: SC.TextFieldView.extend({ | |
layout: { ... }, | |
valueBinding: "MyApp.editMyRecordController.attr2" | |
}), | |
saveButton: SC.ButtonView.extend({ | |
layout: { ... }, | |
title: "Save", | |
target: MyApp.statechart, | |
action: "saveContent" | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment