我试图通过两个 foreach 循环从我的 viewModel 中的两个不同数组访问信息,但这些项目没有相互嵌套
<tbody data-bind="foreach: runnr">
<tr>
......
<!--ko foreach: $root.options -->
<td data-bind="visible: value"><span data-bind="text: runnr[prop] "></span></td>
<!-- /ko -->
我希望将“可见”设置为选项值属性,但我想根据选项中的道具将跨度文本设置为 runnr 中的属性。
options = ko.observableArray([
{ name: "PP", value: pp, prop: 'Post' },
{ name: "Weight", value: weight, prop: 'Weight' },
{ name: "Price", value: price, prop: "Price" }]);
runnr = ko.observableArray([
{Post:1, Weight:125, Price:12000},
{Post:2, Weight:124, Price:15000}
]);