knockout.js - Knockout - data is not retrieved from an observable array -


i'm developing part of web gui displays vm sets available during tenant creation in cloud. object representing set looks this:

function boxtemplate(data) {     var self = this;     self.id = ko.observable(0);     self.name = ko.observable("");     self.description = ko.observable("");      if (data) {         self.id(data.id);         self.name(data.name);         self.description(data.description);     } } 

in next step i'm trying retrieve ids array fo above objects. code following:

var boxtemplatesids = ko.observablearray([]);  (var = 0; < self.boxtemplateslist.length; i++) {     boxtemplatesids.push(self.boxtemplateslist()[i].id); }  var boxtemplatesidsasjson = ko.tojson(boxtemplatesids); 

the boxtemplatesidsasjson passed argument in request body. however, when print it, it's empty , null passed appropriate argument in underlaying rest api. tried different approaches, none. can me figure out wrong code? i'd grateful. :)

if self.boxtemplateslist observable array of boxtemplate objects, id property ko.observable, , need use round brackets it's value (self.boxtemplateslist()[i].id()):

for (var = 0; < self.boxtemplateslist.length; i++) {     boxtemplatesids.push(self.boxtemplateslist()[i].id()); } 

or using map:

var boxtemplatesids = ko.observablearray(self.boxtemplateslist().map(     function(item) { return item.id(); } )); 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -