【发布时间】:2012-11-04 01:25:46
【问题描述】:
我有以下代码:
/* Sample data received from an ASP.Net WebApi ajax call */
var data = { [{"CodSeguro":676541,"NroSeguro":538178},{"CodSeguro":687069,"NroSeguro":577836]},{"CodSeguro":123,"NroSeguro":233]};
/*This function build the view model that will be shared by multiple pages*/
function getViewModel(data)
{
return ko.mapping.fromJS(data);
}
var viewModel = getViewModel(data);
ko.applyBindings(viewModel);
我的 Html 如下所示:
<table>
<thead>
<tr>
<th>CodSeguro</th>
<th>NroSeguro</th>
<th>NroEndoso</th>
</tr>
</thead>
<tbody data-bind="foreach: ">
<tr>
<td>
<span data-bind="text: CodSeguro"></span>
</td>
<td>
<span data-bind="text: NroSeguro"></span>
</td>
<td>
<span data-bind="text: NroEndoso"></span>
</td>
</tr>
只是我不知道在这一行的 foreach 后面放什么:
我真的需要使用 Mapping Plugin,因为我不想在这两个地方编写很多 ob 对象(用于敲除的 js 和服务层中的 c#)
小提琴是这样的:
谢谢!!!
【问题讨论】:
标签: knockout.js asp.net-web-api knockout-mapping-plugin