knockout.js options binding not reflecting added item -


the page shows original list of advisers properly. however, when attempt use push() method array, list size updates, select option list on page not update. need tell knockout update or something? here sample code:

function updatestudentadviserlist(student) {     var list = viewmodel.studentadvisers();         if (student.isstudentadviser() == "true" || student.isstudentadviser() == true) {         var alreadyinlist = false;         (var = 0; < list.length; i++) {             alert(list[i].id);             if (list[i].id == student.id()) {                 return;             }         }          list.push(student);         alert('new size: ' + list.length);     } else {         (var = 0; < list.length; i++) {             alert(list[i].id);             if (list[i].id == student.id()) {                 list.splice(i, 1);                 alert('new size: ' + list.length);                 break;             }         }     } } 

function viewmodel(data) {     var self = this;         this.studentadvisers = ko.observablearray(data); } 

you made changes js array not observablearray. have notify knockout changes. can call valuehasmutated this.

function updatestudentadviserlist(student) {     var list = viewmodel.studentadvisers();         if (student.isstudentadviser() == "true" || student.isstudentadviser() == true) {         var alreadyinlist = false;         (var = 0; < list.length; i++) {             alert(list[i].id);             if (list[i].id == student.id()) {                 return;             }         }          list.push(student);         alert('new size: ' + list.length);     } else {         (var = 0; < list.length; i++) {             alert(list[i].id);             if (list[i].id == student.id()) {                 list.splice(i, 1);                 alert('new size: ' + list.length);                 break;             }         }     }      viewmodel.studentadvisers.valuehasmutated(); } 

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 -