Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdaringe/f70c81fb81d1448e49e2 to your computer and use it in GitHub Desktop.
Save cdaringe/f70c81fb81d1448e49e2 to your computer and use it in GitHub Desktop.
var Model = require('ampersand-model');
var View = require('ampersand-view');
var domready = require('domready');
var MyModel = Model.extend({
props: {
id: {
type: 'integer',
default: null
}
},
children: {
child: Model
}
});
var modelA = new MyModel();
modelA.child = new MyModel({id: 503});
console.log(modelA.child.id);
var MyView = View.extend({
template: '<div id="root"><textarea data-hook="log"></textarea>' +
'<div data-hook="dummy"></div></div>',
bindings: {
'model.child.id': { // details is a child state
type: 'text',
hook: 'dummy'
}
},
events: {
'keyup [data-hook=log]': 'handleLogChange'
},
render: function() {
this.renderWithTemplate();
}
});
MyView.prototype.handleLogChange = function(evt) {
this.model.child.id = this.model.child.id + 1; // TODO DEBUG WHY IS BINDING NOT UPDATING
};
module.exports = MyView;
domready(function() {
var myView = new MyView({
el: window.document.getElementById('sandbox'),
model: modelA
});
myView.render();
});
@cdaringe
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment