後端回傳 JSON 結構:
{
"existList": [{"isgd":"1","usernumber":"110"},{"isgd":"1","usernumber":"112"}],
"newBacklist": []
}
var data = JSON.parse(responseText); // 或 $.parseJSON
var existRows = data.existList; // 直接取得陣列
var newRows = data.newBacklist;
$('#dgExist').datagrid('loadData', existRows);
$('#dgNew').datagrid('loadData', newRows);
// TypeScript 介面
interface ResponseData {
existList: UserInfo[];
newBacklist: UserInfo[];
}
interface UserInfo { isgd: string; usernumber: string; }
// 使用
const res: ResponseData = JSON.parse(responseText);
this.existData = res.existList;
this.newData = res.newBacklist;
loadData 接受陣列,自動渲染列(需預先定義 columns)。{total: 100, rows: [...]} 並用 loadData 或 datagrid({data: ...})。[] 會顯示空表格,不報錯。| 錯誤 | 原因 | 修正 |
|---|---|---|
| 顯示 [object Object] | 未定義 columns 或 field 不匹配 | 檢查 columns field 與 JSON key 大小寫一致 |
| 資料不更新 | 未呼叫 loadData 或 datagrid('reload') | 確認觸發渲染 |
| 日期格式錯誤 | JSON 日期為字串 | 用 formatter 格式化或後端統一 ISO 8601 |