backbone-events

Backbone View: Inherit and extend events from parent

喜欢而已 提交于 2019-11-26 11:46:09
问题 Backbone\'s documentation states: The events property may also be defined as a function that returns an events hash, to make it easier to programmatically define your events, as well as inherit them from parent views. How do you inherit a parent\'s view events and extend them? Parent View var ParentView = Backbone.View.extend({ events: { \'click\': \'onclick\' } }); Child View var ChildView = ParentView.extend({ events: function(){ ???? } }); 回答1: One way is: var ChildView = ParentView.extend

Backbone 0.9.9: Difference between listenTo and on

假如想象 提交于 2019-11-26 10:18:47
问题 I am trying to learn the new changes they did in Backbone 0.9.9. Currently I got problems to understand the difference between listenTo and on : listenTo var View = Backbone.View.extend({ tagName: \"div\", intialize: function() { this.listenTo(this.model, \'change\', this.render); }, render: function() { this.$el.empty(); this.$el.append(\'<p>hello world</p>\'); } }); on var View = Backbone.View.extend({ tagName: \"div\", intialize: function() { this.model.on(\'change\', this.render, this); }

Backbone: event lost in re-render

主宰稳场 提交于 2019-11-26 09:23:14
问题 I have super-View who is in charge of rendering sub-Views . When I re-render the super-View all the events in the sub-Views are lost. This is an example: var SubView = Backbone.View.extend({ events: { \"click\": \"click\" }, click: function(){ console.log( \"click!\" ); }, render: function(){ this.$el.html( \"click me\" ); return this; } }); var Composer = Backbone.View.extend({ initialize: function(){ this.subView = new SubView(); }, render: function(){ this.$el.html( this.subView.render()