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

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -