我不會,淘汰賽foreach不起作用。爲什麼不工作淘汰賽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 -->
您是否收到任何錯誤訊息?究竟發生了什麼? – 2012-07-18 09:44:02
它發生了,但應該顯示2項 – Mediator 2012-07-18 09:59:16
嗨,'@ ko.Apply(Model)'是什麼,這不是正常的剃刀語法,你使用某種插件嗎? – CallumVass 2012-07-18 11:58:44