I have the following view model which contains an array of elements
function ReservationsViewModel() {
var self = this;
self.availableMeals = [
{ mealName: "Standard (sandwich)", price: 0, id = 1 },
{ mealName: "Premium (lobster)", price: 34.95, id = 2 },
{ mealName: "Ultimate (whole zebra)", price: 290, id = 3 }
];
}
I want to bind this view model to a input, but i want to bind only the Single array element meal name that has the id value as the data-id attribute of the input.
<input type="text" id="firstElementMealName" data-id="1" data-bind="value: ??"></input>
In this example i would bind the array element with id = 1, and the text would appear as "Standard (Sandwich)", but i still need the full binding and change tracking (observables) and all the other good stuff in Knockout.
How to pick up the data-id and use it in the binding code to bind the appropriate meal to the input?
Thanks in advance
Suggested solution:
In the view:
EDIT: here is a two-way solution:
In the View: