Created
January 14, 2015 23:34
-
-
Save cdaringe/f70c81fb81d1448e49e2 to your computer and use it in GitHub Desktop.
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
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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTML sourcing in the browserified file posted above