用户表中关联公司表,后台查询分页后返回的json数据为
{
"pageSize": 0,
"pageNum": 0,
"total": 12,
"offset": 0,
"rows": [
{
"id": 10,
"name": "xqy",
"age": 12,
"password": null,
"gender": "1",
"description": "",
"companyDto": {
"companyId": 2,
"companyName": "信息中心",
"companyAddress": "广州花都"
}
},
{
"id": 11,
"name": "test1",
"age": 18,
"password": null,
"gender": null,
"description": "",
"companyDto": {
"companyId": 3,
"companyName": "营销委",
"companyAddress": "广州天河"
}
}
]
}
其中rows和total是bootstrap-table固定需要的字段,读取数据时自动根据columns的配置来读取相应的field,但是当需要读取公司信息companyDto时,这时候需要使用formatter,columns配置如下
columns: [{
checkbox : true
}, {
field: 'id',
title: '学号'
}, {
field: 'name',
title: '姓名'
}, {
field: 'gender',
title: '性别'
}, {
field: 'age',
title: '年龄'
}, {
field: 'description',
title: '描述'
}, {
field: 'companyDto',
title: '公司',
formatter : function(value,row, index){ //主要配置在这里
return value.companyName;
}
}
]
可参考官方文档的说明:http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/#列参数