When calling methods, the this
variable gets assigned on invocation.
var f = $root.myPostProcessingLogic;
f(); // this will not set 'this' to '$root'
The above is essentially what knockout is doing, and this makes this
be bound to something else inside myPostProcessingLogic()
. You have already defined the scoped self
variable, so this is easy to fix.
Another problem is that, reassigning observables won't preserve any subscribers, and any dependant observables won't update.
self.generall = ko.observableArray();
self.myPostProcessingLogic = function(elements) {
self.generall.removeAll();
$('.desti').each(function(i, obj) {
$.getJSON("http://127.0.0.1:8000/api/hotel?format=json&location__name="+obj.value, function(data) {
$.each(data.objects, function(i, item){
self.generall.push(item.name);
});
});
});
}