开发者

backbone.js bound events not delegated to views

开发者 https://www.devze.com 2023-03-15 18:09 出处:网络
When I call the save method on my model the server returns me a new version of the object from the database (even if there have been errors whilst saving).

When I call the save method on my model the server returns me a new version of the object from the database (even if there have been errors whilst saving).

In my model I have:

this.bind("change", function() {
  console.log('CHANGED MODEL');
});

In my view I have:

this.model.bind('change', function() {
  cons开发者_运维百科ole.log('CHANGED MODEL IN VIEW');
});

When I invoke the save method I only get the log from the model (CHANGED MODEL), for some reason the change event is not delegated to the view.

Am I missing something? I cannot for the life of me figure out why the change event in the view is not called when the one in the model is.

Any help is as always muchly appreciated.


It seems to me that you've forgotten to configure the view with the model:

var product = new ProductModel();
var searchView = new ProductSearchView({ model: product });

If I'm wrong, you'll have to give us more code.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号