當一個頁面里存在多個table表格時,加載頁面通過以下方式獲取表格數據:
var tableIns = table.render({
elem: '#purchaseList',
url: ctx + '/purchase/list',
height: "full-125",
page: true,
limits: [10, 15, 20, 25],
id: "purchaseListTable",
cols: [[
{field: "id", title: '編號', fixed: "true", width: 80},
{field: 'purchaseNumber', title: '采購單號', minWidth: 50, align: "center"},
{field: 'purchaseDate', title: '日期', minWidth: 50, align: "center"},
{field: 'supplierName', title: '供應商', minWidth: 100, align: 'center'},
{field: 'amountPayable', title: '金額', minWidth: 100, align: 'center'},
{field: 'userName', title: '操作員', minWidth: 100, align: 'center'},
{field: 'remarks', title: '備注', minWidth: 100, align: 'center'},
{title: '操作', minWidth: 150, templet: '#purchaseListBar', fixed: "right", align: "center"}
]]
});
var tableIns02 = table.render({
elem: '#purchaseListGoods',
url: ctx + '/purchaseListGoods/list',
height: "full-125",
page: true,
limits: [10, 15, 20, 25],
id: "purchaseListGoodsTable",
cols: [[
{field: 'code', title: '葯品編碼', minWidth: 50, align: "center"},
{field: 'name', title: '葯品名稱', minWidth: 50, align: "center"},
{field: 'model', title: '規格', minWidth: 100, align: 'center'},
{field: 'price', title: '單價', minWidth: 80, align: 'center'},
{field: 'num', title: '數量', minWidth: 70, align: 'center'},
{field: 'unit', title: '劑型', minWidth: 100, align: 'center'},
{field: 'total', title: '總金額', minWidth: 80, align: 'center'},
{title: '操作', minWidth: 70, templet: '#purchaseListGoodsBar', fixed: "right", align: "center"}
]]
});
可以通過layui.table.cache.【tablename】分別獲取表格的數據(數據分頁時,是當頁還是全部還在驗證);tablename為上面代碼標紅部分