jquery autosuggest ui conditional return statement
I am using jquery autosuggest ui. and it works fine. However, is that possible to have conditional return statement. If I do that my jquery blows up.
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+") ",
};
}
Your brackets are all over the place. Change it to this:
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+") "
}
}));
精彩评论