I need to update an observable array element value. The observable array is a collection of class objects. First I need to find out matching object by id and update some other p
That's pretty simple with knockout:
// We're looking for the Seat with this No
var targetNo = 2;
// Search for the seat -> arrayFirst iterates over the array and returns the
// first item that is a match (= callback returns "true")!
var seat = ko.utils.arrayFirst(this.seats(), function(currentSeat) {
return currentSeat.No() == targetNo; // <-- is this the desired seat?
});
// Seat found?
if (seat) {
// Update the "Booked" property of this seat!
seat.Booked(true);
}
http://jsfiddle.net/2NMJX/4/