I have a problem with my knockout implementation. I am new to knockout so would appreciate the help.
I have the following code:
function updateViewModel() {
if (typeof groupId == 'undefined') {
groupId = getDefaultGroupId();
}
$.getJSON("api/livestatusgroup/children/" + groupId)
.done(function (data) {
ko.mapping.fromJS(data, liveStatusViewModel.groups);
groupsLoaded();
});
$.getJSON("api/livestatusgroup/resources/" + groupId)
.done(function(data) {
ko.mapping.fromJS(data, liveStatusViewModel.resources);
resourcesLoaded();
});
this.resourceImagePath = ko.computed(function () {
return "../Image/" + this.ResID;
}, this);
}
function ViewModel() {
var self = this;
self.resources = ko.mapping.fromJS([]);
self.groups = ko.mapping.fromJS([]);
}
var vm = new ViewModel();
ko.applyBindings(vm);
Unfortunately, the computed observable function resourceImagePath is not correctly capturing the ResID for my resource, so I end up with urls like /Image/undefined.
What am I missing? I have checked and the ResID field definitely exists in the view model.
S
updateViewModel()function (what objectthisrefers to?). 2. Anyway yourcomputedwouldn't work whis way, because it's not subscribed toResID, regardles is itobservableor not. - atamanupdateViewModel(). - ataman