Created
July 15, 2014 22:03
-
-
Save HenrikJoreteg/b8245278d5a50e6a7461 to your computer and use it in GitHub Desktop.
How you might do a subview for a child model property
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'); | |
module.exports = Model.extend({ | |
props: { | |
address: 'state' | |
} | |
}); |
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 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