I'm using Knockout AMD Helpers to load ViewModels, with the 'module binding' feature.
Usually, when I need to load remote data I use a deferred object to ensure that ko.ApplyBindings is only called after all my data is available on the ViewModel.
I created a sample jsfiddle to illustrate my issue using a delayed ajax call:
self.initialize = function () {
self.name("This is a sample article");
self.getArticleTypes(self.articleTypes);
};
self.getArticleTypes = function (observableArticleTypes) {
var fakeData = {
delay: 5
};
$.ajax({
async: true,
cache: false,
type: 'post',
url: '/echo/json/',
data: fakeData,
success: function (data) {
observableArticleTypes([{
id: 1,
articleType: 'Breaking News'
}, {
id: 2,
articleType: 'Weather'
}]);
console.log("Data loaded from server");
}
});
};
How can I architect my code, using the AMD Helpers but delaying the ApplyBindings until all my data is ready on the ViewModel?