This works fine:
var vm = {};
$.getJSON('file.json', function (data) {
vm.objects = data;
});
ko.applyBindings(vm);
But this doesn’t work:
var vm = {
objects: $.getJSON('file.json', function (data) {});
};
ko.applyBindings(vm);
Why not?
Thanks
Because $.getJSON doesn’t return anything (or, at least, it doesn’t return your data). It’s asynchronous, so the only way to access the data is in the callback function.