【问题标题】:how I can add extra my attribute into bootstrapTable我如何将额外的属性添加到 bootstrapTable
【发布时间】:2016-05-01 23:54:13
【问题描述】:

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

但我需要在我的 td 标签中进行控制,因为在 td 标签中添加一些额外的属性 正如我在代码“数据符号”属性中所写 ,但插件将其删除 谁能帮帮我

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>
        

【问题讨论】:

    标签: javascript jquery twitter-bootstrap datatables bootstrap-table


    【解决方案1】:

    我认为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>
            

    【讨论】:

    • 嗨,我想添加任何属性
    猜你喜欢
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-20
    • 1970-01-01
    • 1970-01-01
    • 2012-06-16
    相关资源
    最近更新 更多