knockout.js - Knockout observable array randomly doesn't bind -


i'm having problem durandal/knockout/sammy - not sure 1 culprit. var roots = ko.observablearray([]); doesn't bound ui. of time works perfectly. on sees don't.

vm activate:

var activate = function () {         groupsdata.getroots().then(function (data) {             roots($.map(data, function (it) { return new groupnode.groupnode(it); })); //if console.log(roots()); right here, correct data shows         });     }; 

datacontext:

var getroots = function () {     return q.when($.getjson(url)); }; 

my view: if hit refresh on , over, span 'length' in show correct length of time. 0 , ui inside of foreach not show.

    <span data-bind="text: roots().length"></span>     <ul data-bind="foreach: roots">         //bla     </ul> 

you need return promise in activate function, otherwise won't know when promise has completed.

var activate = function () {     return groupsdata.getroots().then(function (data) {         roots($.map(data, function (it) { return new groupnode.groupnode(it); }));     }); }; 

if this, databinding wont occur until promise has finished, remove race condition seeing.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -