简体   繁体   English

为什么Backbone.Modelbinder只绑定视图列表的最后一个实例

[英]Why does Backbone.Modelbinder only bind the last instance of a list of views

In a list of items, every item has its' own modelbinder object to bind the models' values. 在项目列表中,每个项目都有其自己的modelbinder对象以绑定模型的值。

The problem that I'm having could be reproduced: http://jsfiddle.net/goodafternoon/NmgkY/#base 我遇到的问题可以重现: http : //jsfiddle.net/goodafternoon/NmgkY/#base

Only the last element that appears in the list gets bound and thus only the that element responds to the models event listener 只有出现在列表中的最后一个元素被绑定,因此只有那个元素才能响应模型事件侦听器

this.on("change", function() {
    console.log('event');
});

I'm using ironcooks famous Modelbinder module : https://github.com/theironcook/Backbone.ModelBinder 我正在使用Ironcooks著名的Modelbinder模块: https : //github.com/theironcook/Backbone.ModelBinder

Fixed it. 固定它。

If you had a similar problem, here is the updated fiddle: http://jsfiddle.net/goodafternoon/XwT2k/1/ 如果您遇到类似的问题,请参见以下更新的提琴: http : //jsfiddle.net/goodafternoon/XwT2k/1/

The problem was that I was creating a new instance of the ModelBinder object in the class rather than creating it when the model is instantiated, so there was only ever one ModelBinder, which is why I only ever got the binding on one element. 问题是我在类中创建了ModelBinder对象的新实例,而不是在实例化模型时创建了它,所以只有一个ModelBinder,这就是为什么我只绑定到一个元素的原因。

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

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