ko.applyBindings can only be called once for each section. If you do not pass the second parameter, the section is a whole page. If you have a specific section, such as a DIV , you should pass it as the second parameter.
Or, you can create one view model for a page with a property for both lists and simply link your page to this single view model. I recommend this approach. This code might look like this:
var ViewModel = function() { this.administrators = ko.observableArray([]); this.definedRoles = ko.observableArray([]); }; var vm = new ViewModel(); ko.applyBindings(vm); $.getJSON("/api/administrators", function (data) { vm.administratos(data); }); $.getJSON("/api/roles", function (data) { vm.definedRoles(data); });
Remember, since ko.applyBindings only needs to be called once, you must do this as soon as possible. Calling from ajax methods is usually a bad idea for several reasons. First, the ajax method can no longer be reused as an update call; and two, the other functions of the page must wait for the ajax method to return in order to start working.
source share