How could I replace a observable array's content by storing it in another variable , say for example:
I have an observable array: var list = self.StateList();
And I want to do like this:
var cities = self.CityList();
//console.log(cities);
var oldLocation = ko.utils.arrayFirst(cities, function (item) {
return item.CityId == args.CityId;
});
cities.replace(oldLocation, args);
But it is showing error cities has no method replace,
UPDATE I tried with this anwser , it some how helped me I used observable slice method , it helped some how:
var cities = self.CityList();
var observble = ko.observable();
observble(cities.slice(0));
So my all cities observable will be copied into a brand new observable
Now i can do what ever i want as it is same observable array of my cities. Somebody can think like why to convert observable array to variable and again converting it to observable array. I have a requirement to send my observable array to a function. If there is any other better solution please post it over here.