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

http://jsfiddle.net/pqn32/

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

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -