简体   繁体   中英

backbone.js bound events not delegated to views

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() {
  console.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.

Vincent.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM