Backbone.js的:在巴顿认为,影响采集不同的样板 [英] backbone.js: Button in view that affects a different model in collection

查看:134
本文介绍了Backbone.js的:在巴顿认为,影响采集不同的样板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始用Backbone.js的打算。到目前为止,我真的很喜欢它。

我有这样的事情:


  • MODELA

  • ModelB

  • ViewA

  • ViewB

MODELA持有ModelB集合

如何建立ModelB的ViewB一个按钮,点击后,集合中的变化在下一ModelB实例属性?


解决方案

  VAR山坳= this.model.collection;
变种nextModel = col.at(col.indexOf(this.model)+1)
如果(nextModel)nextModel.set({whatevar});

您不必跟踪父集合中,骨干会为你。
您应该检查,如果你是在收集也结束。

I'm just getting going with backbone.js. So far, I'm really liking it.

I have something like this:

  • ModelA
  • ModelB
  • ViewA
  • ViewB

ModelA holds a collection of ModelB

How can I build a ViewB of ModelB with a button which, when clicked, changes an attribute on the next ModelB instance in the collection?

解决方案

var col = this.model.collection;
var nextModel = col.at( col.indexOf(this.model) + 1)
if(nextModel) nextModel.set({whatevar});

You do not need to keep track of the parent collection, backbone does it for you. You should check if you are at the end of the collection also.

这篇关于Backbone.js的:在巴顿认为,影响采集不同的样板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆