knockout.js - knockout js observable array removing all items -
i new knockout js. trying remove item knockout observable array. remove function removing items in array. can me on this?
the following how viewmodel looks like
function reservationsviewmodel() { var self = this; self.availablemeals = ko.observablearray([ { mealname: "standard (sandwich)", price: 0 }, { mealname: "premium (lobster)", price: 34.95 }, { mealname: "ultimate (whole zebra)", price: 290 } ]); self.seats = ko.observablearray([]); self.addseat = function() { self.seats.push(self.availablemeals()); } self.removeseat = function(seat) { self.seats.remove(seat) } } ko.applybindings(new reservationsviewmodel());
here js fiddle
thanks,
praveen.
every time call self.availablemeals()
, the same array object back. not an object same properties , values, the same object. means self.seats
contains multiple copies of same object.
knockout's remove
function removes items ===
argument pass in, in case means remove all items source array since identical.
since not using actual pushed value anywhere, can push dummy value instead:
self.addseat = function() { self.seats.push({}); }
Comments
Post a Comment