后台返回的数据格式和bootstrap-table默认的格式不同怎么改?

bootstrap-table的数据格式为

[
    {
        "id": 0,
        "name": "测试11111",
        "price": "¥0",
        "column1": "c10",
        "column2": "c20",
        "column3": "c30",
        "column4": "c40"
    },
    {
        "id": 1,
        "name": "测试1",
        "price": "¥1",
        "column1": "c10",
        "column2": "c20",
        "column3": "c30",
        "column4": "c40"
    },
    {
        "id": 2,
        "name": "测试2",
        "price": "¥2",
        "column1": "c10",
        "column2": "c20",
        "column3": "c30",
        "column4": "c40"
    },
    {
        "id": 3,
        "name": "测试3",
        "price": "¥3",
        "column1": "c10",
        "column2": "c20",
        "column3": "c30",
        "column4": "c40"
    },
    {
        "id": 4,
        "name": "测试4",
        "price": "¥4",
        "column1": "c10",
        "column2": "c20",
        "column3": "c30",
        "column4": "c40"
    }
    ]





后台返回我的格式为

{
  "msg":"查询成功",
  "errcode":0,
  "data":{
    "rows":[
      {
        "id":"17",
        "pharmacy_id":"4",
        "drug_id":"6",
        "price":"6.00",
        "update_time":"2017-02-15 10:22:21",
        "create_time":"2017-02-15 10:22:21",
        "status":"1",
        "drug_name":"苦参",
        "p_price":"20.00",
        "unit_text":"支"
      },
      {
        "id":"16",
        "pharmacy_id":"4",
        "drug_id":"5",
        "price":"5.00",
        "update_time":"2017-02-15 10:22:20",
        "create_time":"2017-02-15 10:22:20",
        "status":"1",
        "drug_name":"甘草",
        "p_price":"5.00",
        "unit_text":"袋"
      },
      {
        "id":"15",
        "pharmacy_id":"4",
        "drug_id":"4",
        "price":"4.00",
        "update_time":"2017-02-15 10:22:16",
        "create_time":"2017-02-15 10:22:16",
        "status":"1",
        "drug_name":"干姜",
        "p_price":"10.00",
        "unit_text":"克"
      }
    ],
    "total":"6"
  }
}

格式不一样 表格获取不到数据怎么改?

阅读 13.9k
3 个回答

已解决,加上这个就好了

responseHandler: function(res) {
                return {
                    "total": res.data.total,//总页数
                    "rows": res.data.rows   //数据
                 };
            },

为什么我照你的这样写的还是不行呢 急急急 求楼主回答 除咯这里这样写 columns里面有什么特殊的写法吗

你个坑货。。。我解决咯。。。你这样根本不行。。。。。

新手上路,请多包涵

根据server或client作分页时,table的data传参方式不一样

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏