I have the following observable array, which gets the data from a WebAPI using Breeze when the view is activated (at the activate() function on Durandal)
var prices = ko.observableArray();
The price class has three attributes: id, name and price.
I then have the following array:
var services = [{
active: true,
name: 'Service1',
price: getPrice('Service1')
}, {
active: true,
name: 'Service2',
price: getPrice('Service2')
}];
What the getPrice(name) function should do is get the object which has the name passed as parameter...
I want to be able to do the following on the view:
<div class="services">
<ul data-bind="foreach: services">
<li data-bind="visible: active, text: name + ' ($' + price.price + ')'"></li>
</ul>
</div>
I've searched a lot on StackOverflow and tried to do this in many ways, but haven't been able to make it work. I'm not sure if I should use ko.utils.arrayFirst(), ko.computed(), or what I should do.. I've tried many approaches without success.