在使用Easyui的表單提交的時(shí)候父叙,經(jīng)常需要返回Json 數(shù)據(jù)神郊,可是有時(shí) 返回的是Json字符串,不是Json對象趾唱,
字符串中的數(shù)據(jù)無法讀取涌乳。
解決這一問題,需要用到Jquery中的Json對象轉(zhuǎn)換方法:$.parseJSON(str)
這一方法可以將格式正確的Json字符串甜癞,轉(zhuǎn)換成Json對象夕晓,從而正確的讀取其中的數(shù)據(jù)。
范例如下:
$(goods_type_form).form('submit', {
url : 'GoodsTypeAction!getQueryList.action',
dataType : 'text',
success : function(result) {
map = $.parseJSON(result);
alert(map);
alert(map.total);
alert(map.rows);
if (true) {
$('#goods_Type_Grid').datagrid('loadData', map); //將返回的數(shù)據(jù)綁定到datagrid
} else {
$.messager.alert('Info', "沒有找到記錄悠咱!", 'info');
}
}
});