Backbone Design

后端 未结 5 1088
猫巷女王i
猫巷女王i 2020-12-25 10:18

I\'m just getting started with Backbone. I went through the first two PeepCode screencasts which were great and now I\'m digging in on a quick detached (no server side) mock

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 10:41

    From a classical MVC perspective, your views respond to changes in their associated models.

    //initialize for view
    initialize : function() {
        this.model.on("change", this.render(), this);
    }
    

    The idea here is that anytime a view's model is changed, it'll render itself.

    Alternatively or additionally, if you change something on a view, you can trigger an event that the controller listens to. If the controller also created the other models, it can modify them in some meaningful way, then if you're listening for changes to the models the views will change as well.

提交回复
热议问题