javascript - ko does not update binded controls if model is changed programmatically -
my model looks this. multi-functional page , model needs modified sometimes, when specific elements clicked, done using ajax call. update function updates model result, see below. unfortunately, model updates, elements on page stay same :(
function viewmodel(result,currenttheme) { var self = this; self.isblankform = ko.observable(); self.snapedit = ko.observable(); self.snapeditsuccess = ko.observable(); self.ismenotified = ko.observable(); self.isemailsenttouser = ko.observable(); self.fromemailbox = ko.observable(); self.subjectemailbox = ko.observable(); self.themenames = ko.observablearray([]); self.themechoice = ko.observable(); self.bgcolor = ko.observable(); self.frmcolor = ko.observable(); self.txtcolor = ko.observable(); self.btncolor = ko.observable(); self.btntxtcolor = ko.observable(); self.appid = ko.observable(); self.revid = ko.observable(); } var vm = new viewmodel(); function updatemodel(result) { var currenttheme = result.payload.currtheme; vm.isblankform = !(result.payload.isblankform); vm.snapedit = result.payload.emailtext; vm.snapeditsuccess = result.payload.successbody; vm.ismenotified = result.payload.ismenotified; vm.isemailsenttouser = result.payload.isemailsenttouser; vm.fromemailbox = result.payload.fromuseremail; vm.subjectemailbox = result.payload.emailsubject; vm.themenames(result.payload.themelist); vm.themechoice = result.payload.currtheme; vm.bgcolor = result.payload.bgcolor; vm.frmcolor = result.payload.frmcolor; vm.txtcolor = result.payload.txtcolor; vm.btncolor = result.payload.btncolor; vm.btntxtcolor = result.payload.btntxtcolor; vm.appid = result.payload.appid; vm.revid = result.payload.revid; }
knockout observables functions, , need updated calling them this:
function updatemodel(result) { var currenttheme = result.payload.currtheme; vm.isblankform(!(result.payload.isblankform)); vm.snapedit(result.payload.emailtext); vm.snapeditsuccess(result.payload.successbody); vm.ismenotified(result.payload.ismenotified); vm.isemailsenttouser(result.payload.isemailsenttouser); vm.fromemailbox(result.payload.fromuseremail); vm.subjectemailbox(result.payload.emailsubject); vm.themenames(result.payload.themelist); vm.themechoice(result.payload.currtheme); vm.bgcolor(result.payload.bgcolor); vm.frmcolor(result.payload.frmcolor); vm.txtcolor(result.payload.txtcolor); vm.btncolor(result.payload.btncolor); vm.btntxtcolor(result.payload.btntxtcolor); vm.appid(result.payload.appid); vm.revid(result.payload.revid); }
further reading
- observables : see section, reading , writing observables
Comments
Post a Comment