After update i need to replace a item in the ko array. The problem is with the replace function i need to have the old item.
Here is my function:
self.saveMarket = function (market) {
var item = ko.toJS(market);
$.ajax({
type: (item.MarketId != "" ? 'PUT' : 'POST'),
url: url + (item.MarketId != "" ? '?id=' + item.MarketId : ''),
data: item,
success: function (data) {
self.Markets.push(market);
self.showList();
},
error: function (err) {
alert(err);
},
});
}
This should handle both insert and update. The insert works with the push(market), but if i do an update, how can i replace the old item with the new?
Thanks in advice