简体   繁体   English

将集合绑定到Backbone.js中的视图

[英]Binding collections to views in Backbone.js

I am new to backbone and I am stuck with this problem where I need to bind a Collection to a view. 我刚接触骨干,并且一直困扰着这个问题,我需要将Collection绑定到视图。 Is there a way to do this in Backbone or do I have to iterate through my Collection and then bind individuals models to views? 有没有办法在Backbone中做到这一点,还是我必须遍历我的Collection,然后将各个模型绑定到视图? All the examples I found online go through these lines of iterating through the collection (like http://liquidmedia.ca/blog/2011/02/backbone-js-part-3/ ). 我在网上找到的所有示例都遍历了整个集合(例如http://liquidmedia.ca/blog/2011/02/backbone-js-part-3/ )。

If this is the way to do it in Backbone, then my other question is whether there is another framework that does a better job for binding to Collections. 如果这是在Backbone中实现的方式,那么我的另一个问题是,是否还有另一个框架可以更好地绑定到Collections。

Thanks 谢谢

All model events are delegated to the collection as well. 所有模型事件也都委托给集合。 So instead of binding to each models change event you could just bind to the collections change event. 因此,除了绑定到每个模型更改事件之外,您还可以绑定到集合更改事件。 Whenever a model changes the collection triggers the event as well and gives you the model that triggered the event as callback argument. 每当模型更改时,集合也将触发事件,并为您提供触发事件的模型作为回调参数。

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

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