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

发布于 2024-11-18 00:22:22 字数 424 浏览 6 评论 0原文

当我在模型上调用 save 方法时,服务器会从数据库返回对象的新版本(即使保存时出现错误)。

在我的模型中,我有:

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

在我看来,我有:

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

当我调用保存方法时,我只从模型(更改的模型)获取日志,由于某种原因,更改事件没有委托给视图。

我错过了什么吗?我一生都无法弄清楚为什么视图中的更改事件没有被调用,而模型中的更改事件却被调用了。

一如既往,我们非常感谢任何帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空袭的梦i 2024-11-25 00:22:22

在我看来,您似乎忘记了使用模型配置视图:

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

如果我错了,您将不得不为我们提供更多代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文