我遇到了一个问题,其中一个已创建对象中的字段是undefined
. 这是对象:
var Collateral = Collateral || {};
Collateral.NoteModel = function(config) {
"use strict";
this.loanId = config.loanId;
this.docId = config.docId;
this.borrowerName = config.borrowerName;
this.funder = config.funder;
this.docsDrawn = config.docsDrawn;
this.firstPayment = config.firstPayment;
this.loanAmount = config.loanAmount;
this.interestRate = config.interestRate;
this.dateDocsIn = config.dateDocsIn;
this.status = config.status;
this.eventDate = config.eventDate;
this.submittedBy = config.submittedBy;
};
我正在存储对象列表,并且对象的每个字段都正确存储,但status
字段除外。当我自己调用该status
字段时,它会返回正确的值,但是当我尝试访问note.status
它时会返回undefined
.
下面是创建对象列表的代码:
var renderNotesList = function(url, data, elementId, liFunc) {
$.getJSON(url, data, function(response) {
var notesList = [];
renderNotesList.divider;
$(elementId).empty();
$(response).each(function() {
var entry = $(this)[0];
var note = new Collateral.NoteModel({ //initialize note object
loanId: entry["Loan_ID"],
docId: entry["Doc_ID"],
borrowerName: entry["Borrower_Name"],
funder: entry["Funder"],
docsDrawn: entry["Docs_Drawn"],
firstPayment: entry["First_Payment"],
loanAmount: entry["Loan_Amount"],
interestRate: entry["Interest_Rate"],
dateDocsIn: entry["Date_Docs_In"],
status: entry["Event_Type"],
eventDate: entry["Event_Date"],
submittedBy: entry["Submitted_By"]
});
console.log(entry["Event_Type"]); // here the value is correct
console.log(note.status); // here the value is "undefined"
var li = liFunc(note, renderNotesList.divider);
li.appendTo($(elementId));
try {
$(elementId).listview('refresh');
}
catch(e) {
return;
}
});
});
};
对于所有其他note.
调用,变量都是正确的。只是status
返回undefined
。对象存储了正确的值,但过了一会儿,没有改变任何东西,值变成了undefined
. 有任何想法吗?提前致谢!