Im trying to access information from two different arrays within my viewModel with two foreach loops, but the items are not nested within each other
<tbody data-bind="foreach: runnr">
<tr>
......
<!--ko foreach: $root.options -->
<td data-bind="visible: value"><span data-bind="text: runnr[prop] "></span></td>
<!-- /ko -->
I want ‘visible’ to be set to the options value property, but the span text I want set to a property from runnr based on the prop from options.
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}
]);
You should be able to use
$parent[prop]to access therunnrthat you are looping over.Simplified fiddle: http://jsfiddle.net/rniemeyer/y3R43/