ObservableArray is not refreshed in Knockout

The problem is that knockout does not map successfully objects when they are null. So if you want everything to work ok you should not just pass any object to your model but you must select the fields from it like:

 $.each(data.commentsData.comments, function(i, item){
      model.comments.push({_id: item.id, createdBy: {name: item.createdBy.name}, text: item.text, children: item.children}); 
 });

You will know when your model is not an ObservableArray when you try calling it with brackets (). So if you try:

model.comments = ko.observableArray()
model.comments() //This should print a function. If it says null then it is not instantiated as it should be

Select your data when your ObservableArray is not updating. Do not push everything into it.

You may also like...