如何将数据(所选项目)传递到Durandal组成的详细视图? [英] How to pass data (selected item) to Durandal composed detail view?

查看:98
本文介绍了如何将数据(所选项目)传递到Durandal组成的详细视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(从几个小时前开始)我已经开始使用 Durandal ,希望可以管理视图并允许撰写在单个页面中-以前的方法(也使用Knockout)太笨拙,无法在胖HTML文件中进行维护。



我已经安装/设置了Durandal,我可以创建视图和视图模型-但是,我不知道如何将数据放入视图模型中,以用作新视图模型的基础



'p>例如,我有选择的项目是左侧导航栏 - 当一个项目被选中它更新了选择项在当前的模型观察到的,但它应该的在右侧加载正确的详细视图:因为部分原因尝试使用Durandal分离组件/视图,所以这应该来自单独的视图/视图模型。



我已经阅读了包括 Com的文档位置使用合成,但是关于 how 将数据传递给viewmodel对我来说还不清楚。似乎我可以使用具有现有模型的视图(在当前视图/范围内),但我真的很想仅使用一些当前模型数据(即id)来获取真实模型数据



因此,我的问题




  • 如何将初始数据(例如选定项)传递给处理的viewmodel?我宁愿使用声明性的 compose:绑定,因为这是使KO .. KO的原因。


  • 具有/传递初始数据的概念这里的正确方法,还是有更好的选择?我已经看到 activeItem隐约提及,但是细节/用法使我感到困惑。







更新1:我发现我们如何共享视图之间的数据/将数据视图传递给视图,但实际实施中缺乏响应。我真的不希望在父子(不同的视图/视图模型对)之间共享视图模型,并且我想使用声明式方法(没有事件)。父母不需要知道孩子,但是需要从父母那里得到孩子的数据。






更新2:尽管上面我暗示仅需要 id,但我想使用一种与 any 基础对象一起使用的方法,路由器不一定适合该方法。在这种情况下,深层链接不是问题。但是,如果您认为路由器是实现此目标的方法,请发布有关此参数(带有详细信息)的答案作为答案,我至少会给它一个赞成票。.

解决方案

如果您查看微风的源代码,则可以看到一个主从方法的示例。



他们正在使用激活器来构成子视图。



https://github.com/IdeaBlade/Breeze/blob/master/Samples/TempHire/TempHire/App/viewmodels /resourcemgt.js



我不知道您是否在使用微风,但是这种方法与如何获取数据无关。


I've started using (as of, a few hours ago) Durandal with the hope to manage views and allow composition within a single page - the previous approach, also using Knockout, was getting too unwieldy to maintain in a fat HTML file.

I've installed/setup Durandal and I can create views and viewmodels - however, I don't know how to get data into the viewmodel to use as a basis for the new viewmodel.

For instance, I have a "left nav bar" for selecting items - when an item is selected it updates a "selected item" observable in the current model, but it should also load the correct "detail view" in the right: because part of the reason to try Durandal to separate the components/views, this should come from a separate view/viewmodel.

I've read through the documentation including Composition and Using Composition, but the method as to how to pass data to the viewmodel is not clear to me. It seems like I could use a view with an existing model (in the current view/scope), but I'd really like to merely use some of the current model data (i.e. an id) to fetch the "real" model data in the view.

Thus, my questions;

  • How is passing initial data, such as the "selected item" to a viewmodel handled? I would prefer to use the declarative "compose:" binding, as that is what make KO .. KO.

  • Is this notion of having/passing initial data the correct way here, or is there a better alternative? I have seen "activeItem" vaguely mentioned, but the details/useage aludes me.


Update 1: I've found How do we share the data between views/Pass the data view to view, but the responses are lacking in actual implementation. I'd really like to not share the viewmodel between parent-child (distinct view/viewmodel pairs) and I'd like to use a declarative approach (no events). The parent need not know about the child, but the child needs to be fed data from the parent.


Update 2: While above I hinted only the "id" was required, I would like an approach that works with any basis object, which the router is not necessarily suitable for. Deep linking is not a concern in this case. However, if you feel the router is the way to approach this, post an argument for such (with details) as an answer and I'll at least give it an up-vote ..

解决方案

If you look at the breeze source code, you can see an example of a master-detail approach.

They are using an activator to compose the child view.

https://github.com/IdeaBlade/Breeze/blob/master/Samples/TempHire/TempHire/App/viewmodels/resourcemgt.js

I don't know if you are using breeze or not, but the approach is independent of how do you get the data.

这篇关于如何将数据(所选项目)传递到Durandal组成的详细视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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