KnockoutJS - 主视图中的多个局部视图? [英] KnockoutJS - Multiple partial views within on main view?

查看:76
本文介绍了KnockoutJS - 主视图中的多个局部视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将现有的asp mvc app移植到使用knockoutjs(纯js / html),因为我不再需要asp mvc中的任何功能。然而,我可以预见的一个问题是我处理我的一些页面的方式。

I am trying to port an existing asp mvc app over to use knockoutjs (pure js/html) as I no longer really need any of the functionality within asp mvc. However one problem I can forsee is the way I am handling some of my pages.

我有一个页面包含大约12个部分视图,每个部分都有自己的模型。现在使用Knockout JS,你似乎每页只有1个viewmodel / view,但是我所拥有的页面包含大量信息,这些部分类似于:

I have one page which contains about 12 partial views, each partial has its own model. Now with Knockout JS it seems like you should only really have 1 viewmodel/view per page, however the page I have contains a large amount of information, the sections would be akin to:


  • 客户详情

  • 客户地址

  • 客户近期订单

  • 客户卡

  • 客户资金

  • ...

  • Customer Details
  • Customer Address
  • Customer Recent Orders
  • Customer Cards
  • Customer Funds
  • ...

如果部分细节发生变化,使事情变得更加棘手,则需要更改另一部分的数据。所以,让我们说你删除一张卡然后需要告诉资金控制它不再有卡,所以不会有资金。 (这是一个抽象的例子,但希望说明这一点)

To make things more tricky if some details change in on part, it needs to change data in another part. So lets say you remove a card it then needs to tell the funds control that it no longer has a card so wont have funds. (This is all an abstract example, but hopefully illustrates the point)

所以我有点不确定如何在淘汰赛中做到这一点,因为我宁愿把它作为一个大模型,我会很高兴,但它包含大量的信息。除了多个表单,因为您可以更新您的地址而无需更新其他所有内容。

So I am a bit unsure how to do this in knockout, as that would rather have it as one big model, which I would be happy with doing but it contains ALOT of information. As well as multiple forms, as you can update your address without having to update everything else.

因此,我应该为此视图制作一个大型模型并处理它?或者有没有办法让观点相互交谈?

So should I just make one large model for this view and just deal with it? or is there a way to have views talk to each other?

推荐答案

我的策略是使用一个大视图模型。无论你怎么说,部分视图都是服务器端的概念,一旦所有内容都转移到客户端,一页中就会有大量的数据信息。

My strategy is to use a one large view model. No matter you put it, the partial views are a server-side concept and once everything transfers to the client side, it would be large amount of data information in a single page.

然而,为了使事情易于管理,我确保每个Javascript操作代码都写在它自己的部分视图中。这样可以更容易地跟踪功能及其各自的代码。

However to make things manageable I ensure that every Javascript manipulation code is written in it's own Partial view. This makes it easier to track functionality and it's respective code.

所以基本上你在主页面填充主Customers数组对象,然后调用函数来填充Details,Addresses等。分别在每个局部视图中定义。

So basically you populate your main Customers array object in the main page and then call functions to populate Details, Addresses etc. which are respectively defined in each of the partial view.

这篇关于KnockoutJS - 主视图中的多个局部视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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