There is issue which I am facing right now.I have observable array which contains list of objects.Whenever I updating property of any object of array.It is not reflected on browser.I have use all knockout functions like replace,remove.But the updation coming in observable array but not in browser.
Here is a sample of my issue:
var ViewModel=new {
self=this;
self.List=ko.observableArray([]);
}
$(function(){
ko.applyBinding(ViewModel);
})
$.post('/url',{},function(data){
ViewModel.List(data); //data is list having 4 property having CommentList as again object-->id,title,description,CommentList--->commenttitle,commentdescription
})
//During change of property of commentList
$.post('/updateComment',{},function(obj){//Here obj-->obj.Commenttitle="some title",obj.commentdescription='some description'
//Let say there require update 4th object of List and 2nd property of CommentList
ViewModel.AnswerList()[4].CommentList.splice(2,1,obj);
})
//But nothing updation on browser
You say:
The properties on the objects in the observable array also need to be set to
ko.observable
for your UI to be automatically updated.For example:
would NOT update your UI as
name
is not an observable.However,
..would update your UI to display the name B as
name
is an observable.EDIT: (After code was added to question)
So from your code you have:
assuming
GetAnswerFromViewModel
returns an answer with observable properties, you should be writing:If the properties on your answer are not observables then your UI will not update.