开发者

getting all values in the row

var patientInfo = {}   
patientInfo.patientID = row.patientID;
patientInfo.firstName = row.firstName;
patientInfo.lastName = 开发者_运维知识库row.lastName;
patientInfo.dateOfBirth = row.DateOfBirth;
patientInfo.age = row.age;
patientInfo.gender = row.gender;

When I print I patientInfo, I get only one row's data... how can I get all row's data?


Not quite sure what you mean. But assuming you are having this code in a loop, you are always overwriting the patientInfo data. Add them to an array:

infos = []

for(.....) {
    var patientInfo = {}   
    patientInfo.patientID = row.patientID;
    patientInfo.firstName = row.firstName;
    patientInfo.lastName = row.lastName;
    patientInfo.dateOfBirth = row.DateOfBirth;
    patientInfo.age = row.age;
    patientInfo.gender = row.gender;

    infos.push(patientInfo)
}

It would be good to know here row is coming from. Maybe you could just do:

infos = []

for(.....) {
    infos.push(row)
}

or maybe you don't have to do this at all. You have to provide more information.

More information => better answers.


To iterate over properties in an object, use for in.

for (var property in patientInfo) {
   alert(property);
}

Keep in mind, however, that if someone has augmented Object, its enumerable properties will be iterated over too.

You can mitigate this by using hasOwnProperty().

for (var property in patientInfo) {
   if ( ! patientInfo.hasOwnProperty(property)) {
       continue;
   }
   alert(property);
}

Alternatively, you could specify you own toString() method which formats the values however you want. Be sure to return a string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜