0

I have a json string which is feeding a javascript page, I am trying to render on the screen, by using the following code, but my conditional logic is not working, what I want to accomplish is if there is not data returned print a blank space, otherwise show and icon. Thanks.

JSON

"SCHEDULES":{ "RCOUNT":186, "SCHEDULE":[ { "CASEID":18397020.000000, "SCHEDAREA":"SURG", "LASTDIETORDERNAME":"", "LASTDIETORDERSTARTDT":"", }

Javascript

var dietTable = [];

dietTable.push(
    "<table id='dataTable' class='dataTable' cellpadding=0 cellspacing =0>"
        ,"<tr id='dataTableTH'>"
            ,"<th class='headers' style='text-align:left;white-space: nowrap;'>Diet</th>"
            ,"<th class='headers' style='text-align:left;white-space: nowrap;'>Date Time</th>"
        ,"</tr>"
);
dietTable.push(
    "<tr>"
        ,"<td style='vertical-align:top;text-align:left'>",ptDiet,"</td>"
        ,"<td style='vertical-align:top;text-align:left'>",ptDietDT,"</td>"
    ,"</tr>"
);
dietTable.push("</table>");

if(SCHEDULES.LASTDIETORDERSTARTDT !== null) {
    dietVal = ['<img border =0 src="..//..//images//dietIcon2.png " width="20px" height="20px" title="'+dietTable.join("")+'">'];
} else {
    dietVal = ["&nbsp;"];
}
Tony77
  • 311
  • 2
  • 5
  • 25
  • 1
    Please define "not working". Have you checked the value of `SCHEDULES.LASTDIETORDERSTARTDT` before condition? What is it? – Teemu Nov 04 '14 at 14:54
  • 1
    how are we supposed to help troubleshoot a conditional if you don't provide data sample? I doubt you want to use an expicit `!== null` – charlietfl Nov 04 '14 at 15:06
  • Sorry, I meant to say is still showing the icon wether there is a value in SCHEDULES.LASTDIETORDERSTARTDT or no. – Tony77 Nov 04 '14 at 15:11
  • so my guess, is that is comparing only to the first element of the array, how can I loop through it? – Tony77 Nov 04 '14 at 15:12
  • Maybe not an exact dup, but [useful reading](http://stackoverflow.com/a/359509/1169519) about equals operators. – Teemu Nov 04 '14 at 15:31

1 Answers1

0

This Did it, thanks

if(SCHEDULES.LASTDIETORDERSTARTDT !== "")

Tony77
  • 311
  • 2
  • 5
  • 25