1
我在我的web應用程序中使用了Pager JS,Knockout和Jquery。下面的代碼Pager JS參數和敲除
function ViewModel(){
var self = this;
self.interior = ko.observable();
self.interior.background = ko.computed(function() {
$.getJSON('/interiors', {interior_id: self.interior_id()}).success(function(data) {
return self.interior.background = data.interior.background_url;
});
}, this);
}
$(document).ready(function() {
pager.Href.hash = "#!/";
viewModel = new ViewModel();
pager.extendWithPage(viewModel);
ko.applyBindings(viewModel);
pager.start();
});
當代碼被執行,我得到以下錯誤:
Uncaught TypeError: Object #<ViewModel> has no method 'interior_id'
據我所知,該變量尚不存在,而她沒有的方法。但如何解決這個錯誤?
唐不叫一個不存在的函數?您想做什麼? – SLaks
所以我想做 - 當參數'interior_id'改變時,從JSON頁面獲取數據並更新'interior'變量。也許你有什麼建議? – Rustery
但是,在視圖模型中甚至沒有屬性或可觀察屬性,稱爲'interior_id'? –