简体   繁体   English

backbone.js 绑定事件未委托给视图

[英]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).当我在 model 上调用 save 方法时,服务器会从数据库中返回一个新版本的 object(即使保存时出现错误)。

In my model I have:在我的 model 我有:

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.当我调用 save 方法时,我只从 model(更改模型)获取日志,由于某种原因,更改事件未委托给视图。

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.我一生都无法弄清楚为什么当 model 中的那个事件是时不调用视图中的更改事件。

Any help is as always muchly appreciated.一如既往地非常感谢任何帮助。

Vincent.文森特。

It seems to me that you've forgotten to configure the view with the model:在我看来,您似乎忘记使用 model 配置视图:

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

If I'm wrong, you'll have to give us more code.如果我错了,您将不得不给我们更多代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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