Backbone JS: can one view trigger updates in other views?

前端 未结 7 1239
失恋的感觉
失恋的感觉 2020-12-23 02:20

In my simple project I have 2 views - a line item view (Brand) and App. I have attached function that allows selecting multiple items:

var BrandView = Backbone.V         


        
7条回答
  •  渐次进展
    2020-12-23 02:55

    You can use Backbone object as the event bus.

    This approach is somewhat cleaner but still relies on Global Backbone object though

    var view1 = Backbone.View.extend({
    
      _onEvent : function(){
        Backbone.trigger('customEvent');
      }
    
    });
    
    
    var view2 = Backbone.View.extend({
    
      initialize : function(){
        Backbone.on('customEvent', this._onCustomEvent, this);
      },
    
      _onCustomEvent : function(){
        // react to document edit.
      }
    
    });
    

提交回复
热议问题