[英]How can I share data between views in rappidjs
I build a menu view component with rappidjs which has a list of entries in it. 我使用rappidjs构建了一个菜单视图组件,该组件中包含条目列表。 I also have some modules. 我也有一些模块。
I want the module to register their menu entry. 我希望模块注册其菜单项。 I thought building a Manager or a collection but this seems way to heave to me. 我本以为建立经理或收藏夹,但这似乎让我感到困惑。 Is there a simple way? 有没有简单的方法?
Implementation can be found here. 可以在这里找到实现。
http://try.rappidjs.com/project/52b0d1e13bce060342000013 http://try.rappidjs.com/project/52b0d1e13bce060342000013
Checkout the rappidjs.com website, it also uses a menu combined with the ModuleLoader. 请访问rappidjs.com网站,该网站还使用了与ModuleLoader结合使用的菜单。
In https://github.com/rappid/rappidjs.com/blob/master/public/app/Index.xml the menu is build with 在https://github.com/rappid/rappidjs.com/blob/master/public/app/Index.xml中 ,菜单使用
<nav>
<ui:ItemsView items="{pages}" tagName="ul" class="nav">
<js:Template name="item">
<li selected="{isPageSelected(item)}">
<a href="${item.link}">${item.label}</a>
</li>
</js:Template>
</ui:ItemsView>
</nav>
See https://github.com/rappid/rappidjs.com/blob/master/public/app/IndexClass.js for the implementation of isPageSelected
. 有关isPageSelected
的实现,请参见https://github.com/rappid/rappidjs.com/blob/master/public/app/IndexClass.js 。
For a reusable solution, you could a menu component that gets the ModuleLoader
as attribute and dynamically get all registered modules from the moduleLoader.$modules
array. 对于可重用的解决方案,您可以使用一个菜单组件,该组件将ModuleLoader
作为属性,并从moduleLoader.$modules
数组动态获取所有已注册的模块。
We haven't built such a component, because a menu can contain more items than the registered ones in the ModuleLoader. 我们没有构建这样的组件,因为菜单所包含的项目比ModuleLoader中注册的项目更多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.