我没有,淘汰赛 foreach 不起作用。
看法:
@using PerpetuumSoft.Knockout
@using WebIdea.Domain.Entities
@model WebIdea.Web.Models.KnockoutProductList
@{
ViewBag.Title = "Index";
var ko = Html.CreateKnockoutContext();
}
<script src="/Scripts/knockout-2.1.0.js" type="text/javascript"></script>
<script src="/Scripts/knockout.mapping-latest.js" type="text/javascript"></script>
<script src="/Scripts/perpetuum.knockout.js" type="text/javascript"></script>
@ko.Apply(Model)
@using (var items = ko.Foreach(m => m.Products))
{
<ul>
<li>@items.Html.TextBox(x=>x.Url)</li>
</ul>
}
模型:
public class KnockoutProductList
{
public List<Product> Products { get; set; }
}
html:
<script src="/Scripts/knockout-2.1.0.js" type="text/javascript"></script>
<script src="/Scripts/knockout.mapping-latest.js" type="text/javascript"></script>
<script src="/Scripts/perpetuum.knockout.js" type="text/javascript"></script>
<script type="text/javascript">
var viewModelJs = {"Products":[{"Id":"6d222412-87f1-402e-b705-27a89c1572dd","Name":"asdasd","Price":123123,"Url":"http://www.ya.ru/hh33.jpg"},{"Id":"d578f8f3-a6f1-415c-9fd9-7848709cf8e0","Name":"twertwert","Price":12.3,"Url":"http://jewelry.ecommanager.net/uploads/images/products/42eb3d1c-4e7f-41eb-8238-becaaaff100a-thumb.jpg"}]};
var viewModel = ko.mapping.fromJS(viewModelJs);
ko.applyBindings(viewModel);
</script>
<!-- ko foreach: Products -->
<ul>
<li><input data-bind="value : Url" /></li>
</ul>
<!-- /ko -->