Reputation: 2928
I have a view model with two observable arrays:
assignedItems
requiredDropPoints
In the view I want do something like this
<ul>
<!-- ko foreach: assignedItems -->
<li>
<!-- display item-->
</li>
<!-- /ko -->
<!-- ko foreach: requiredDropPoints-->
<li>
<!-- display different item-->
</li>
<!-- /ko -->
</ul>
I can do ko if: expression
after the first foreach
and it works fine, but the 2nd foreach
won't work. Is there a way to get what I need?
Upvotes: 0
Views: 170
Reputation: 7641
You can wrap your collections with ko.computed and bind list items to resulting computed:
composite = ko.computed(function() {
var result = [];
result.push.apply(result, assignedItems());
result.push.apply(result, requiredDropPoints());
return result;
});
<ul>
<!-- ko foreach: composite -->
<li>
<!-- display item-->
</li>
<!-- /ko -->
</ul>
In this composite you can also filter items, map them or do some additional processing.
Upvotes: 1