hi,
i would solve this adding more object orientation to it :
1. class which manages the stock , find entry call init with new data or add new entry if not found
2. class which represents a stock entry:
function StockEntry(data){
var self = this,
self.quantity = ko.observable();
self.stock = ko.observable();
self.stockChanged = ko.observable(false);
self.init = function(data){
self.quantity(data.quantity );
self.stock(data.stock);
}
this.stock.subscribe(function(newVal){
this.stockChaged(true);
// perhaps setTimeout to reset value
});
self.init(data);
}
<style>
.highlighted {background-color:#yellow;}
</style>