javascript - 如何将额外的属性添加到 bootstrapTable 中

标签 javascript jquery twitter-bootstrap datatables bootstrap-table

我使用了 bootstrapTable.js 插件 https://github.com/wenzhixin/bootstrap-table 要创建数据表,我用 Json 填充表

但我需要控制我的 td 标签,在 td 标签中添加一些额外的属性 正如我在代码“data-symbole”属性中所写 ,但插件将其删除 谁能帮帮我吗

var x = 
[
    {
        "id": 0,
        "name": "test0",
        "price": "$0"
        ,"pricesymbole":"$"
    },
    {
        "id": 1,
        "name": "test1",
        "price": "$1"
      ,"pricesymbole":"$"
    },
    {
        "id": 2,
        "name": "test2",
        "price": "$2"
      ,"pricesymbole":"$"
    },
    {
        "id": 3,
        "name": "test3",
        "price": "$3"
      ,"pricesymbole":"$"
    }
];

$(function () {
    $('#table').bootstrapTable({
        data: x
    });
});
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- Latest compiled and minified CSS -->


<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.js"></script>

<table id="table">
    <thead>
        <tr id="tr_{{id}}">
            <th data-field="id">Item ID</th>
            <th data-field="name">Item Name</th>
            <th data-field="price" data-symbole="pricesymbole">Item Price</th>
        </tr>
    </thead>
</table>
        

最佳答案

我认为 formatter 选项对于您的情况很有用:

var x = 
[
    {
        "id": 0,
        "name": "test0",
        "price": "0"
        ,"pricesymbole":"$ "
    },
    {
        "id": 1,
        "name": "test1",
        "price": "1"
      ,"pricesymbole":"¥"
    },
    {
        "id": 2,
        "name": "test2",
        "price": "2"
      ,"pricesymbole":"$ "
    },
    {
        "id": 3,
        "name": "test3",
        "price": "3"
      ,"pricesymbole":"¥"
    }
];

$(function () {
    $('#table').bootstrapTable({
        data: x
    });
});

function priceFormatter(value, row) {
    return row.pricesymbole + value;
}
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- Latest compiled and minified CSS -->


<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.10.1/bootstrap-table.min.js"></script>

<table id="table">
    <thead>
        <tr id="tr_{{id}}">
            <th data-field="id">Item ID</th>
            <th data-field="name">Item Name</th>
            <th data-field="price" data-formatter="priceFormatter">Item Price</th>
        </tr>
    </thead>
</table>
        

关于javascript - 如何将额外的属性添加到 bootstrapTable 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36973316/

相关文章:

javascript - 为 Dojo 文本框定义 CSS

javascript - 为什么 window.requestFileSystemSync 未定义?

html - Bootstrap 输入和选择 padding-left 跨浏览器问题

php - 保存 RichText(所见即所得输出)的最佳方式是什么?

javascript - 传单,如何绘制类似油漆(画笔)的形状

jquery - 获取 anchor id 并转换为 JavaScript 数组

jQuery 鼠标悬停效果

php - Js Validator Plugin Remote Rules for Unique Value Checking without Refresh Page 在 Ajax 调用后不起作用

html - 使用 Bootstrap 在页面上居中媒体对象

javascript - 如何创建 Bootstrap Popover 关闭选项