Skip to content

Instantly share code, notes, and snippets.

@HenrikJoreteg
Created July 15, 2014 22:03
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 HenrikJoreteg/b8245278d5a50e6a7461 to your computer and use it in GitHub Desktop.
Save HenrikJoreteg/b8245278d5a50e6a7461 to your computer and use it in GitHub Desktop.
How you might do a subview for a child model property
var Model = require('ampersand-model');
module.exports = Model.extend({
props: {
address: 'state'
}
});
var View = require('ampersand-view');
var ViewSwitcher = require('ampersand-view-switcher');
module.exports = View.extend({
template: '<div><div role="address"></div></div>',
render: function () {
this.renderWithTemplate();
this.switcher = new ViewSwitcher(this.getByRole('address'));
this.model.on('change:address', this.handleAddressChange, this);
// run it manually too
this.handleAddressChange();
},
handleAddressChange: function () {
var self = this;
// This could just as easily be done just by rendering a template
// not entirely sure this actually needs to be this dynamic.
// seems like an address doesn't really need to be bound???
this.switcher.set(new AddressView({
model: self.model.address
}));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment