layui的table参数条件缓存问题

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条
posted @ 2019-05-15 18:04  土了个豆  阅读(7167)  评论(0编辑  收藏  举报