using knockout via durandal (v. 1.2) knockout observable doesn't update binding after being updated result of ajax call, except first time.
viewmodel:
define(["require", "exports"], function(require, exports) { var = (function () { function about() { var _this = this; this.code = ko.observable("initial content"); $.get("myxml.xml", function (data) { return _this.dataloaded(data); }, "text"); } about.prototype.dataloaded = function (data) { this.code(data.tostring()); }; return about; })(); return about; }); view:
<div> <h2>about</h2> <p data-bind="text: code"></p> </div> the viewmodel being bound view via durandals composer, i've run same problem vanilla knockout. content of file correctly displayed first time view composed, when view composed again after binding not updated after initial value. file loaded, , code update observable called, no errors thrown. i've solved problem delaying update setinterval. combined fact works first time, me suggest race condition bug. can't figure out problem be.
is there time period shouldn't update observable? , there pattern avoid this?
edit
for i'm using viewattached method (durandal) know when it's safe update, still know root cause, , possible better solutions.
initializing stuff should safe there. use activate hook , return promise in there. not sure 1 prefered event. root problem guess because of lack of promise ajax call. try changing or @ least use $.ajax async: false.
Comments
Post a Comment