Skip to content

Instantly share code, notes, and snippets.

@topherfangio
Created June 16, 2011 16:07
Show Gist options
  • Save topherfangio/1029586 to your computer and use it in GitHub Desktop.
Save topherfangio/1029586 to your computer and use it in GitHub Desktop.
Basic SC Bindings Example
...
editingPane: MyApp.editingPane.extend({}),
...
...
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();
}
...
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