简体   繁体   English

使用Knockout进行部分查看的对象列表

[英]List of objects to partial view using Knockout

I'm currently in the process of converting an application into Knockout. 我目前正在将应用程序转换为淘汰赛。 Currently there are a number of views that within them will loop round a list of objects within the model to then pass to a partialview to render that object. 当前,其中有许多视图将在模型中的对象列表周围循环,然后传递到partialview来渲染该对象。

<div>
    foreach (var item in Model.ListData) {
            Html.RenderPartial("~/Views/Shared/_ListPanel.cshtml", item);
            }
        }
</div>

In my knockout view model I have the same list of objects as an observable array. 在剔除视图模型中,对象列表与可观察数组相同。 What would be the best way to pass each of them to the parital view and bind using knockout? 将它们中的每个传递到parital视图并使用敲除进行绑定的最佳方法是什么?

Use a foreach binding to iterate through the elements: 使用foreach绑定来遍历元素:

<!-- ko foreach: Children -->
    //your partial view
<!-- /ko -->

Inside the partial view bind to the properties of the object as appropriate. 在局部视图中,视情况绑定到对象的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM