錯誤信息:
Cannot read property length of undefined
Cannot read property length of null
場景描述:
在使用easyui 中數據表格DataGrid時,模擬代碼如下:
$('#tt').datagrid({
title:'Frozen Columns',
iconCls:'icon-save',
width:500,
height:250,
url:'$!basePath/xxx/xxx',
frozenColumns:[[
{field:'itemid',title:'Item ID',width:80},
{field:'productid',title:'Product ID',width:80},
]],
columns:[[
{field:'listprice',title:'List Price',width:80,align:'right'},
{field:'unitcost',title:'Unit Cost',width:80,align:'right'},
{field:'attr1',title:'Attribute',width:100},
{field:'status',title:'Status',width:60}
]]
});
注意這一行:
url:'$!basePath/xxx/xxx'
,Controller返回給DataGrid是一個JSON,
但不要爲null,不要爲null,不要爲null
當返回爲null的時候,瀏覽器控制檯會報一個Cannot read property length of null的錯誤。