layui的table在render的時候,會將部分參數緩存下來,以至於在開發過程中發現,layui的reload方法似乎有“緩存”的功能.
原因:在某博客發現,table內部是采用的繼承的方法.
var tableObj = table.render({
elem: '#LAY-WASTE-CONTRACT'
,page: false
,url: baseurl4 + "/" + contractId
,even: true
,headers: {
access_token: layui.data(setter.tableName).access_token,
}
,cols: [[
{type: 'numbers', title: '序號', unresize: true},
{field: 'wasteCategory', title: '廢物類別', key: true},
{field: 'wasteName', title: '廢物名稱', key: true},
{field: 'unitPrice', title: '單價', event: "unitPrice", key: true},
{field: 'wasteWeight', title: '重量', key: true, templet: '#test'},
{field: 'wasteMoney', title: '危廢金額', key: true}
]]
,skin: 'line'
,height: '160'
,done:function () {
console.info(this);
delete this.where;
//在done回調里面,此表格對應的數據及配置結構
}
});
console.info(tableObj.config);
//在done回調里面,此表格對應的數據及配置結構
{limit: 10, loading: true, cellMinWidth: 60, text: {…}, checkName: "LAY_CHECKED", …}
cellMinWidth: 60
checkName: "LAY_CHECKED"
cols: [Array(6)]
done: ƒ ()
elem: pe.fn.init [table#LAY-waste-contract, context: document, selector: "#LAY-waste-contract"]
even: true
headers: {access_token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyRGVwd…iMSJ9.Rl1ato3oziezxCK037jTnjYRxn5ZRuzsdYJC1abYO-I"}
height: "160"
id: "LAY-waste-contract"
index: 9
indexName: "LAY_TABLE_INDEX"
limit: 10
loading: true
page: false
request: {pageName: "page", limitName: "limit"}
response: {statusName: "code", statusCode: 0, msgName: "msg", dataName: "data", countName: "count"}
skin: "line"
text: {none: "無數據"}
url: "http://10.32.2.195:8089/OABackend/market/mwwasteinfo/getContractId/2856edc8-17f9-425e-b030-41ce88ca1a25"
where: {}
__proto__: Object
//在外面接收到的返回對象
{limit: 10, loading: true, cellMinWidth: 60, text: {…}, checkName: "LAY_CHECKED", …}
cellMinWidth: 60
checkName: "LAY_CHECKED"
cols: [Array(6)]
done: ƒ ()
elem: pe.fn.init [table#LAY-waste-contract, context: document, selector: "#LAY-waste-contract"]
even: true
headers: {access_token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyRGVwd…iMSJ9.Rl1ato3oziezxCK037jTnjYRxn5ZRuzsdYJC1abYO-I"}
height: "160"
id: "LAY-waste-contract"
index: 9
indexName: "LAY_TABLE_INDEX"
limit: 10
loading: true
page: false
request: {pageName: "page", limitName: "limit"}
response: {statusName: "code", statusCode: 0, msgName: "msg", dataName: "data", countName: "count"}
skin: "line"
text: {none: "無數據"}
url: "http://10.32.2.195:8089/OABackend/market/mwwasteinfo/getContractId/2856edc8-17f9-425e-b030-41ce88ca1a25"
where: {}
__proto__: Object
可見兩個對象是相同的,有參數的話會發現where里面是有屬性的,並且url等參數在reload的時候都會被保留.
所以解決reload緩存的問題:
在reload的配置內,將參數重新賦值. 比方說
url : ' '
where:{ status : 0 }
或者 將條件參數刪除 delete this.where;
另外,如果想取消分頁,除了 page:false ,有時還需加上 limit: 999 ,因為雖然不分頁,但是默認還是10條
