jquery - parse JSON null values to get ? -
i'm parsing json object (from yql) includes null values, this:
{ "color": "red", "size": null, "brand": "nike", }, { "color": null, "size": "xxl", "brand": "reebok", }, { "color": "blue", "size": "small", "brand": null, },
i'm using jquery generate markup it:
function (data) { $("#content").html('<table></table>'); $.each(data.query.results.row, function (i, item) { $("table") .append('<tr><td class="color">' + item.color + '</td><td class="size">' + item.size + '</td><td class="brand">' + item.brand + '</td></tr>'); });
what can (in jquery ideally) change null's blank space, or @ least put class on td? is:
so rather getting
<td>null</td>
i either
<td> </td>
or
<td class="hidethis">null</td>
you can put inline conditional. equivalent
if( expr. ) {return true} else {return false} <td class="brand">' + ( item.brand == null ) ? ' ' : item.brand + '</td></tr>'
Comments
Post a Comment