2011-08-26 70 views
0

我正在使用jquery autosuggest ui。它工作正常。但是,有可能 有條件返回語句。如果我這樣做,我的jquery爆炸。jquery autosuggest ui條件返回語句

response ($.map(data.data, function(item){ 
    return { 
     if (item.secT = '') { 
      label: item.bodydata+" ("+item.desc+") ", 
      value: item.bodydata+" ("+item.stringid+") ", 
     }else { 
      label: item.bodydata+" ("+item.desc+") " +" ("+item.sec+") ", 
      value: item.bodydata+" ("+item.stringid+") ", 
     }; 
    } 
+0

條件是什麼? – Blazemonger

+1

您的語法已損壞。你不能用JS做到這一點。 – Finbarr

+0

它只是一個縮進問題 – erik

回答

1

您的括號內全是這個位置。將其更改爲:

response ($.map(data.data, function(item){ 
    return 
     item.secT == '' ? { 
      label: item.bodydata+" ("+item.desc+") ", 
      value: item.bodydata+" ("+item.stringid+") " 
     } : { 
      label: item.bodydata+" ("+item.desc+") " +" ("+item.sec+") ", 
      value: item.bodydata+" ("+item.stringid+") " 
     } 
})); 
+0

對不起,這只是一個縮進 – erik

+0

@erik:試試我的代碼,你會看到它的作品。 –

+0

我收到一條錯誤消息:遺失財產編號 – erik