json - if else in javascript leading to missing values -
i have data in json format . follows json string:
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"}]};
in above josn string , half of values reading name has heart rate , rest half body temperature.
then, have piece of code add values:
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)] ]);
problem: above statements, getting value heart rate , nothing @ body temperature. seems wrong in above piece of code ?
you have used single "=" sign in if statement. compare need use "==" in if statement.
Comments
Post a Comment