Return the "undefined" field in an object

I have a problem when one of the fields in the created object is undefined . Here's the object:

 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; }; 

I save a list of objects, and each field of the object is stored correctly, except for the status field. When I call the status field on its own, it returns the correct value, but when I try to access note.status , it returns undefined .

Here is the code to create a list of objects:

 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; } }); }); }; 

For all other note. calls note. the variables are correct. Only status returns undefined . Objects kept the correct values, but after a while, without changing anything, the values โ€‹โ€‹became undefined . Any ideas? Thanks in advance!

+4
source share
1 answer

Since I still cannot comment, I will post as an answer. My assumption is that javascript never talked about the "pass as value / reference" problem. var entry contains all the values โ€‹โ€‹from your JSON and is copied as a reference to your "note" object, but since it is limited in a limited area, these links cease to exist.

Just for testing, try copying some values โ€‹โ€‹directly from the response variable.

0
source

Source: https://habr.com/ru/post/1492407/


All Articles