javascript - Knockout JS - Observable doesn't update the View on Load -
first of all, i'm newbie knockout. got basic understanding. i'm using crossroad routing
this current scenario. value url param.route().plan. work fine
the value set observable in view model. however, binding doesn't work/value doesn't update when navigate route previous using location.href = "checkout/gold" gold plan. if reload page work fine.
ps : view model work expected. doubled confirmed console.log
now code - function redirects problematic view model
// function handling subsription self.subscribe = function () { alert(self.selectedplan()); var currentuser = parse.user.current(); if (currentuser === null) { $('#loginbox').modal('show'); } else { // else redirect location.href = '#checkout/'+self.selectedplan(); // redirect checkout page } } // function ends here
the view model seems work
self.selectedplan = ko.observable(params.route().plan);
view
<span data-bind="text:selectedplan()></span>
okay got answer. maybe someone
use computed observables in such cases. guarantees binding in such cases
var self = this; self.firstname = ko.observable('bob'); self.lastname = ko.observable('smith'); self.fullname = ko.computed(function() { return self.firstname() + " " + self.lastname(); });
their documentations pretty forward
Comments
Post a Comment