我试图通过两个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 -->
我想将'visible'设置为options value属性,但是我想要的span文本根据options中的prop来设置为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}
]);