我有JSON格式的数据。关注我的JSON字符串:
var dataString4 = {"Details":[{"ObservationSource":"Outpatient Clinic","observationValue":98.69999694824219,"ReadingName":"Body Temperature",
"ObservationDateTime":"2014,08,01","ReadingType":"Vitals"},{"ObservationSource":"Outpatient Clinic",
"observationValue":66,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,01",
"ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":98.5,"ReadingName":"Body Temperature","ObservationDateTime":"2014,08,02",
"ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":62,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,02","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":98.4000015258789,"ReadingName":"Body Temperature","ObservationDateTime":"2014,08,15","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":65,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,15","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":98.0999984741211,"ReadingName":"Body Temperature","ObservationDateTime":"2014,08,21","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":61,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,21","ReadingType":"Vitals"},{"ObservationSource":"Outpatient Clinic","observationValue":98.5,"ReadingName":"Body Temperature","ObservationDateTime":"2014,09,01","ReadingType":"Vitals"},{"ObservationSource":"Outpatient Clinic","observationValue":65,"ReadingName":"Heart Rate","ObservationDateTime":"2014,09,01","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":98.69999694824219,"ReadingName":"Body Temperature","ObservationDateTime":"2014,09,07","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":67,"ReadingName":"Heart Rate","ObservationDateTime":"2014,09,07","ReadingType":"Vitals"}]};
在上面的JOSN字符串中,读取名称的一半值具有心率和休息半体温。
然后,我有这段代码来添加值:
for(var i=0; i<queryObjectLen; i++)
{
//console.log(queryObject.Details[i].DeptName);
var ObservationDateTime= new Date(queryObject.Details[i].ObservationDateTime);
var observationValueHeartRate;
var observationValueBodyTempearture;
var value = queryObject.Details[i].ReadingName
if(value ='Heart Rate')
{ observationValueHeartRate= queryObject.Details[i].observationValue;
console.log(ObservationDateTime);
console.log("HeartRate" + observationValueHeartRate);
}
else
{
observationValueBodyTempearture= queryObject.Details[i].observationValue;
console.log(ObservationDateTime);
console.log("bodytemp " + observationValueBodyTempearture);
}
arrdata.addRows([
[ObservationDateTime,parseInt(observationValueHeartRate), parseFloat(observationValueBodyTempearture)]
]);
问题:通过以上陈述,我只获得心率的价值,而对于体温则没有任何价值。上面的代码看起来有什么问题?
答案 0 :(得分:0)
您使用过单曲&#34; =&#34;登录if语句。 比较你需要使用&#34; ==&#34;在if语句中。
答案 1 :(得分:0)
我使用开源项目jinqJs http://www.jinqJs.com来查询您的收藏。
//Use jsJinq.com open source library
var dataString4 = {
"Details":[
{"ObservationSource":"Outpatient Clinic","observationValue":98.69999694824219,"ReadingName":"Body Temperature",
"ObservationDateTime":"2014,08,01","ReadingType":"Vitals"},{"ObservationSource":"Outpatient Clinic",
"observationValue":66,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,01",
"ReadingType":"Vitals"},
{"ObservationSource":"Patient Self Reported","observationValue":98.5,"ReadingName":"Body Temperature","ObservationDateTime":"2014,08,02",
"ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":62,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,02","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":98.4000015258789,"ReadingName":"Body Temperature","ObservationDateTime":"2014,08,15","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":65,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,15","ReadingType":"Vitals"},
{"ObservationSource":"Patient Self Reported","observationValue":98.0999984741211,"ReadingName":"Body Temperature","ObservationDateTime":"2014,08,21","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":61,"ReadingName":"Heart Rate","ObservationDateTime":"2014,08,21","ReadingType":"Vitals"},{"ObservationSource":"Outpatient Clinic","observationValue":98.5,"ReadingName":"Body Temperature","ObservationDateTime":"2014,09,01","ReadingType":"Vitals"},
{"ObservationSource":"Outpatient Clinic","observationValue":65,"ReadingName":"Heart Rate","ObservationDateTime":"2014,09,01","ReadingType":"Vitals"},
{"ObservationSource":"Patient Self Reported","observationValue":98.69999694824219,"ReadingName":"Body Temperature","ObservationDateTime":"2014,09,07","ReadingType":"Vitals"},{"ObservationSource":"Patient Self Reported","observationValue":67,"ReadingName":"Heart Rate","ObservationDateTime":"2014,09,07","ReadingType":"Vitals"}]};
var result = jinqJs().from(dataString4.Details).select();
document.body.innerHTML = '<pre>' + JSON.stringify(result, null, 4) + '</pre>';
然后,您可以对结果执行groupBy或使用聚合函数。如果您想要更多示例,请告诉我。