javascript - Conditionally change display image based on JSON results -


i'm new javascript , jquery , i'm trying display json results in browser. i'm attempting create dynamic html, while inserting json results. here sample of json data:

[{"jobname":"jobdosomething","jobstatus":2,"jobstatusstring":"","jobpath":"\\mart\\controlcenter\\","jobtype":1}, {"jobname":"jobdosomething2","jobstatus":2,"jobstatusstring":"","jobpath":"\\mart\\controlcenter\\","jobtype":1}, {"jobname":"jobdosomething3","jobstatus":4,"jobstatusstring":"","jobpath":"\\mart\\controlcenter\\","jobtype":0} 

here code i'm using display results:

var seqicon = 'img/batchjobicon.gif'; var jobicon = 'img/logo32x32.gif'; for(var = 0; < result.length; i++){                     divs[parseint(divs.length) - 1].innerhtml += '<div id="' + result[i].jobname + '" class="outerdiv">' +                         '<div class="middlediv">' +                             '<div class="innerdiv">' +                                 '<img  id="image" src=' + jobicon + ' />' +                                 /* '<img id="image" src=' + 'if (' + result[i].jobtype + '= 1) {' + "img/batchjobicon.gif" + '} else {' + jobicon + '};' + '/>' + */                                 '<h3>' + result[i].jobname + '</h3>' +                                     '<p class="jobpath">' + result[i].jobpath + ' ' + result[i].jobstatus + ' ' + result[i].jobtype + '</p>' +                                      '<p> <input type="button" id="btnrunjob" class="btn-minimal" value="run job" />' +                                     '<input type="button" id="btngetlog" class="btn-minimal" value="job log" />' +                                     '</p>' +                               '</div>' +                         '</div>' +                         '</div>';                      $('#jobcontainer').append(divs)                 } 

i use line <img id="image" src=' + 'if (' + result[i].jobtype + '= 1) {' + "img/batchjobicon.gif" + '} else {' + jobicon + '};' + '/> (commented out above) able swap desired image based on jobtype json result, not work. insight or suggestions appreciated. thanks.

that line must be:

'<img id="image" src=' + (result[i].jobtype == 1 ? "img/batchjobicon.gif" : jobicon) + '/>' + 

which translates to, if jobtype variable equals 1 output "img/batchjobicon.gif", else output jobicon variable.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -