bootstrapTable组件formatter、responseHandler函数

本文详细介绍了如何使用BootstrapTable组件从服务端获取并展示数据。formatter函数用于自定义列显示,如在用户ID列添加操作按钮;responseHandler函数则用于处理服务器返回的数据,包括提取total、code、msg等信息。示例代码展示了具体实现过程。
摘要由CSDN通过智能技术生成

bootstrapTable组件接受服务端传过来的数据

bootstrapTable组件接受服务端传过来的数据

案例如下:

$(function () {
    var options = {
        id: "bootstrap-table-form",
        url: url,
        showSearch: false,
        showRefresh: false,
        showToggle: false,
        showColumns: false,
        columns: [
            {
			    field : 'userId', 
			    title : '用户ID'
                formatter: function(value, row, index) {
					var actions = [];
       				actions.push("添加相关标签");
                    return actions.join('');
                }
            }],
        responseHandler: function (res) {
            return null;
        }
    };
    $.table.init(options);
});

bootstrap table中formatter函数作用是什么?

formatter: function(value, row, index) {
	var actions = [];
    actions.push("属于列参数");
    return actions.join('');
}

value :代表当前单元格中的值;
row:代表当前行;
index:代表当前行的下标;

bootstrap table中responseHandler函数作用是什么?

返回内容:

{
    "total":10,
    "code":200,
    "msg":"消息内容",
    "rows":[
        {
            "name":"小王"
        },
        {
            "name":"小明"
        }
    ]
}

需要获取totol、code、msg这些消息内容,需要用到上面的函数进行获取操作:

responseHandler: function (res) {
   console.log("total:" + res.total);
   console.log("code:" + res.code);
   console.log("msg:" + res.msg);
   console.log("rows:" + res.rows[0]);
   return null;
}

以上就是bootstrapTable组件formatter、responseHandler函数的具体使用!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
Bootstrap Table Formatter 是一个基于 Bootstrap Table 插件的拓展,它可以帮助开发者快速地为表格中的数据添加格式化显示。使用 Bootstrap Table Formatter,你可以在表格中显示数据的日期、时间、货币、百分比等格式,还可以自定义格式化方式。 Bootstrap Table Formatter 支持的格式化类型包括: - 数字:格式化为货币、百分比等形式; - 日期和时间:格式化为指定的日期和时间格式; - 字符串:截取字符串并添加省略号等效果。 下面是一个使用 Bootstrap Table Formatter 的示例: ```html <table data-toggle="table" data-pagination="true" data-search="true" data-url="data.json"> <thead> <tr> <th data-field="name">名称</th> <th data-field="price" data-formatter="priceFormatter">价格</th> <th data-field="date" data-formatter="dateFormatter">日期</th> <th data-field="status" data-formatter="statusFormatter">状态</th> </tr> </thead> </table> <script> function priceFormatter(value) { return '¥ ' + value.toFixed(2); } function dateFormatter(value) { var date = new Date(value); return date.toLocaleDateString(); } function statusFormatter(value) { if (value === 1) { return '<span class="label label-success">已完成</span>'; } else { return '<span class="label label-danger">未完成</span>'; } } </script> ``` 在这个示例中,我们定义了三个数据格式化函数:`priceFormatter`、`dateFormatter` 和 `statusFormatter`。这些函数将在表格中显示对应字段的数据,并将其格式化为指定的形式。对于 `priceFormatter`,我们将数字格式化为带有货币符号的形式;对于 `dateFormatter`,我们将日期格式化为本地日期字符串;对于 `statusFormatter`,我们根据值的不同,显示不同的状态标签。 通过使用 Bootstrap Table Formatter,我们可以轻松地为数据表格添加格式化显示效果,提升数据展示的易读性和美观性。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

胤墨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值