javascript - Knockout.js Observable Not Getting Set -
i have code not doing suppose do. knockout.js project , object;
self.eventitem = ko.observable({ recordid: ko.observable(0), selectedeventtype: ko.observable() }
this object initialized in function. there lot of code in here debugging while shows "self.originaleventitem().eventtypeid" return value of "6" , number. value set selectedeventtype;
self.loadinitialdata = function () { self.pageloaded(false); var step1 = common.geteventdetailsforedit(self.eventitem().recordid()); //step1 var step2 = step1.then( function (data) { if (data.iserror) { toastr.error(data.errormessage, "error"); return new $.deferred().reject(); } else { self.originaleventitem(data.data); return common.geteventtypes(); } }); //step2 var step3 = step2.then( function (data) { if (data.length > 0) { $.each(data, function (i, item) { self.eventtypes.push(new apollo.dropdowntype(item.recordid, item.name)); self.originaleventtypes.push(item); }); self.eventitem().selectedeventtype(self.originaleventitem().eventtypeid); self.eventtypechanged(); } } );//step3 };//loadinitialdata
now when enter "self.eventtypechanged()" function , call "self.eventitem().selectedeventtype()" return undefined? here function "eventtypechanged()";
self.eventtypechanged = function () { if (self.originaleventtypes) { var newvalue = self.eventitem().selectedeventtype(); (var = 0; < self.originaleventtypes.length; i++) { if (self.originaleventtypes[i].recordid === newvalue) { self.eventitem().selectedfulleventtype(self.originaleventtypes[i]); } } self.resetlists(); self.populatechildlists(); } };
the variable "newvalue" undefined. debugged way through knockout.js , looks being set reason not.
any appreciated.