js el表达式判断是否为空

var customHtml="";
var customMap="${empty customMap}";
if(customMap!="true"){
var customRows=eval('(' + '${customMap}' + ')'); 
var customList=customRows.Rows;
$.each(customList,function(i,obj){      
customHtml+='<tr>'+  
        '<td class="th1">'+obj.phoneNo+'</td>'+
'<td class="th2">'+obj.personName+'</td>'+
'<td class="th3">'+obj.sex+'</td>'+
'<td style="display:none">'+obj.personIdNo+'</td>'
 '</tr>';              
});

}    

在js中使用el表达式,一定要使用引号括起来。否则对象为空的时候,页面会报错。 

使用eval函数将json串转为转为对象:eval('(' + '${customMap}' + ')'); 

如果返回的json中包括双引号,那么就使用单引号包围el表达式,否则,使用双引号。



猜你喜欢

转载自blog.csdn.net/caixiajia/article/details/79025176
今日推荐