背景
项目使用的layui前端框架进行开发,该框架在初始化表格的时候使用到了bootstrap-table,我想页面初始化数据的时候,默认根据不同的参数,显示不同的数据。
JS初始化表格数据的代码
$(function () {
var defaultColunms = UserOperatorInfo.initColumn();
var table = new BSTable(UserOperatorInfo.id, "/request/list", defaultColunms);
UserOperatorInfo.table = table.init();
});
BSTable对象的源码如下:
var BSTable = function (bstableId, url, columns, params) {
this.btInstance = null; //jquery和BootStrapTable绑定的对象
this.bstableId = typeof bstableId == 'string' ? "#" + bstableId : bstableId;
this.url = Feng.ctxPath + url;
this.method = "post";
this.paginationType = "server"; //默认分页方式是服务器分页,可选项"client"
this.toolbarId = typeof bstableId == 'string' ? "#" + bstableId + "Toolbar" : null;
this.columns = columns;
this.height = 665; //默认表格高度665
this.data = {};
this.queryParams = {}; // 向后台传递的自定义参数
this.params = params || {};
};
通过对源码的解读,知道向后端传递自定义参数是通过queryParams对象进行传递的。
正解
下面直接送上这个参数的正确用法:
$(function () {
var defaultColunms = UserOperatorInfo.initColumn();
var table = new BSTable(UserOperatorInfo.id, "/pile_user_station/w/station/list", defaultColunms);
table.queryParams = {'stationId': station.stationId}
UserOperatorInfo.table = table.init();
});
注:这个参数的错误用法如下,引以为戒。
table.setQueryParams('stationId','001')
table.setQueryParams('stationId=001')
table.params.set('stationId','001')
table.queryParams.stationId=001
网友评论