我解析一個JSON對象(從YQL),其中包括一些空值,就像這樣:解析JSON空值得到 ?
{
"color": "red",
"size": null,
"brand": "Nike",
},
{
"color": null,
"size": "XXL",
"brand": "Reebok",
},
{
"color": "blue",
"size": "small",
"brand": null,
},
我使用jQuery來生成它的一些標記:
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>');
});
能有什麼我(在理想情況下,在jQuery中)將null更改爲空格,或者至少在其td上放置一個類?那就是:
,這樣,而不是讓
<td>null</td>
我得到任何
<td> </td>
或
<td class="hidethis">null</td>
更換
item.color
我喜歡的if-else。謝謝! – nathanbweb 2011-02-17 22:42:08