所以我循環了一組JSON數組,然後遍歷每個單獨的數組。如果聲明中斷.push方法
如果我刪除了兩個if語句它會通過兩組數據環和附加的「目標」與兩個「數據」組,但像現在是,它只會通過第一回路的每個追加items.join 。
案件的東西是一個if循環首先,認爲它會很重要,但沒有。
奇怪的是,consoleOut(如console.log)打印我的東西,所以它實際上是通過JSON集內的兩個數組循環。
$.each(data, function(keys, vals)
{
var items = [];
$.each(data[keys], function(key, val)
{
var currString = JSON.stringify(val);
switch (key)
{
case "ID":
consoleOut("ID: "+currString+" loaded");
break;
case "parentIDs":
consoleOut("parentIDs: "+currString);
break;
case "UID":
consoleOut("UID: "+currString);
UID = unquote(currString);
break;
case "title":
consoleOut("Title: "+currString);
items.push('<H1 class="' + key + '">' + unquote(currString) + '</H1>');
break;
case "img":
consoleOut("IMG: "+currString);
if ($(currString).val() !== '')
{
items.push('<IMG class="' + key + '" src='+currString+'></IMG>');
};
break;
case "text":
consoleOut("TXT: "+currString);
if ($(currString).val() !== '')
{
items.push('<P class="' + key + '">'+currString+'</P>');
};
break;
}
});
consoleOut("---------");
$('<DIV/>', {
'id': UID,
html: items.join('')
}).appendTo(target);
}
)
我想知道如何在if語句打破我追加到主「項目」陣..
(當我不字符串化之初它將循環的VAL,但是這因爲if語句是那麼真實,但停止假時工作..所以,也許這是更好地修改我的if語句對於這一點,但我仍然困惑的是在.push停止如何工作的?)
嘗試改變'!==''來!=',看看它是否有效! – linuxeasy 2012-02-25 15:19:16
不,試過 – TrySpace 2012-02-25 15:24:13
是否可以爲你設置一個[jsfiddle](http://jsfiddle.net) – Henesnarfel 2012-02-25 15:26:40