Backbone.js的:观点之间的通信 [英] Backbone.js: communication between views

查看:115
本文介绍了Backbone.js的:观点之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作包含的条目列表的主干应用程序,就像示例应用托多斯(<一个href=\"http://documentcloud.github.com/backbone/examples/todos/index.html\">http://documentcloud.github.com/backbone/examples/todos/index.html).

I'm working on a Backbone app that contains a list of entries, much like the example app Todos (http://documentcloud.github.com/backbone/examples/todos/index.html).

所以,我有一个App查看,每个列表项一个视图。现在,说我有一个全球性的编辑按钮。应用视图将处理点击什么,然后我想要做的是告诉每个列表视图来显示一个删除按钮。

So, I have an App view and one view per list item. Now, say I have a global edit button. The App view would handle a click and what I then want to do is tell each list view to show a delete button.

在下面(从Spotify的)的截图,pressing编辑按钮导致所有列表视图来改变外观。

In the screenshots below (from Spotify), pressing the Edit button causes all list views to change appearance.

什么是与骨干做到这一点的最好办法。我需要遍历所有的列表视图和调用一个函数编辑模式。但应用程序视图(开箱即用)不知道的列表视图。

What's the best way to do this with Backbone. I need to iterate over all list views and call a editMode function. But the App view (out of the box) doesn't know about the list views..

推荐答案

我写了一篇文章对视图之间的协调一些不同的选择,而回:<一href=\"http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/\">http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/

I wrote up an article a while back on a few different options for coordinating between views: http://lostechies.com/derickbailey/2011/07/19/references-routing-and-the-event-aggregator-coordinating-views-in-backbone-js/

在你的情况,我建议你使用事件聚集,我在那篇文章中形容。你可以有每个项目视图听一个编辑模式事件,或类似的东西。当这个事件触发,即听了会更新自己进入编辑模式,每个视图。那么你会怎么做,当你点击完成相反 - 发送一个视图模式事件,或类似的东西,并让每个视图本身更新适当

in your case, i'd recommend using the event aggregator that i describe in that article. you could have each item view listen for a "editmode" event, or something similar. when this event fires, each view that listened for it would update itself to go into edit mode. then you would do the opposite when you click "done" - send a "viewmode" event, or something similar, and have each view update itself appropriately.

这篇关于Backbone.js的:观点之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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