我需要覆盖Knockout对象。但是当我尝试这个时,我得到了以下错误。当页面加载我调用loadXMLFiles并且它没有任何问题。当我尝试覆盖我在downloadFile函数中出现以下错误Uncaught TypeError: Cannot read property 'fromJS' of undefined
的对象时按下按钮。但在这两种情况下,它都是同一个对象。可以请任何人帮我这个???
var urlPath = window.location.pathname;
//var self = this;
$(function () {
ko.applyBindings(indexVM);
indexVM.loadXMLFiles();
});
var indexVM = {
XMLFiles: ko.observableArray([]),
loadXMLFiles: function () {
var self = this;
$.ajax({
type: "GET",
url: "../HotelBackEndProcess/UpdateDatabase/FillIndex",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
self.XMLFiles(data);
},
error: function (err) {
alert(err.status + " : " + err.statusText);
}
});
},
DownloadFile: function () {
Id = this.Id;
var self = this;
$.ajax({
type: "GET",
url: "../HotelBackEndProcess/UpdateDatabase/DownloadFile",
contentType: "application/json; charset=utf-8",
data: { Id: Id },
dataType: "json",
success: function (data) {
ko.mapping.fromJS(XMLFiles, self.data);
},
error: function (err) {
alert(err.status + " : " + err.statusText);
}
});
}
};