-
-
Save antongudkov/d9c57c4f5539a5b61b80 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 SomeModelView = Backbone.View.extend({ | |
initialize: function() { | |
this.model.on('change', this.render, this); | |
}, | |
render: function() { | |
// render a template | |
} | |
}); |
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
initialize: function() { | |
this.listenTo(this.model, 'change', this.render); | |
} |
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 SomeCollectionView = Backbone.View.extend({ | |
initialize: function() { | |
var self = this; | |
this._views = []; | |
// create a sub view for every model in the collection | |
this.collection.each(function(model) { | |
self._views.push(new SomeModelView({ | |
model: model | |
})); | |
}); | |
}, | |
render: function() { | |
var self = this; | |
this.$el.empty(); | |
// render each subview, appending to our root element | |
_.each(this._views, function(subview) { | |
self.$el.append(subview.render().el); | |
}); | |
} | |
}); |
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
render: function() { | |
this.$el.empty(); | |
var container = document.createDocumentFragment(); | |
// render each subview, appending to our root element | |
_.each(this._views, function(subview) { | |
container.appendChild(subview.render().el) | |
}); | |
this.$el.append(container); | |
} |
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
someMethod: function(){ | |
$('foo').bar(); | |
} |
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
someMethod: function(){ | |
this.trigger('someEvent'); | |
} |
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
this.listenTo view1, 'someEvent', this.someMethodCallback |
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
someMethodCallback: function(){ | |
this.$('foo').bar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment