【问题标题】:Meteor and Bootstrap table, How to call detailFormatter functionMeteor 和 Bootstrap 表,如何调用 detailFormatter 函数
【发布时间】:2016-02-15 11:02:58
【问题描述】:

我正在使用Bootstrap table

1: http://bootstrap-table.wenzhixin.net.cn/ 。我已添加 This Package 以导入 Bootstrap-table。

     <table id="table" class="table table-striped"
       data-toolbar="#toolbar"
       data-detail-view="true"
       data-height="460"
       data-pagination="true"
       data-search="true"
       data-sort-name="name"
       data-sort-order="desc"
       data-unique-id="id"
       data-page-list="[10, 25, 50, 100, ALL]"
       data-detail-formatter="detailFormatter"
       data-show-export="true"
       data-show-refresh="true"
       data-show-columns="true"
       data-row-style="rowStyle"
       data-export-types="['csv']">
    <thead>
    <tr>
        <th data-field="id" data-sortable="true">id</th>
        <th data-field="question" data-sortable="true">question</th>
        <th data-field="answer" data-sortable="true">answer</th>
        <th data-field="category" data-visible="true" data-tableexport-display="always">category</th>
    </tr>
    </thead>
</table>

它工作正常,但我有一个必须调用的 detailFormatter 函数来创建行详细信息。基本上是在努力实现This

所以在我的 js 中,我添加了 detailFormatter 函数,但没有工作,那么我应该把 detailFormatter 函数放在哪里工作。

 if (Meteor.isClient) {

function detailFormatter(index, row) {
alert("detailFormatter 1")
                var html = [];
                $.each(row, function (key, value) {
                    console.log("key: "+key);
                    if(key=="answer") {
                        html.push('<p><b>' + key + ':</b> <textarea class="form-control">' + value + '</textarea> </p>');
                        html.push('<button type=button class=update-btn>Update</button>');

                    }
                    if(key=="category"){


                        console.log("category:: "+value)

                        if(value=="application_related"){
                                html.push('<select class="form-control"><option  selected value="application_related">Application Related</option><option value="application_status">Application Status</option></select>');
                        } else {
                            html.push('<select class="form-control"><option  selected value="application_related">Application Related</option><option value="application_status" selected>Application Status</option></select>');
                        }

                        $('select').first().val("application_status");

                        //$('select option[value="' + value + '"]')
                    }
                    if(key=="id"){
                         html.push('<input type="hidden" class="id" value='+ value + '></input>');
                        console.log("category:: "+value)
                    }
                });
                return html.join('');
        }

}

【问题讨论】:

    标签: javascript meteor bootstrap-table


    【解决方案1】:

    我在通过 HTML 定义 rowStyle 时遇到了类似的问题。解决方案是通过JS将函数传递给表。这同样适用于需要传递给引导表的任何函数。

    例如:

    Template.results.onRendered(function(){
        this.$('#table').bootstrapTable({detailFormatter : myFormatterFunction, rowStyle : myRowStyleFunction});
    };
    

    【讨论】:

    • Detail Formatter 假设在表格标题中创建一个新的空白列,但在我的情况下,用于展开详细视图的“+”加号占据了表格的 ID 字段列。我试图找到解决方案,但找不到解决方案。如果可以的话,请帮助我
    猜你喜欢
    • 2018-03-18
    • 2016-03-09
    • 1970-01-01
    • 2023-04-11
    • 2014-10-31
    • 1970-01-01
    • 2015-03-17
    • 1970-01-01
    • 2013-06-10
    相关资源
    最近更新 更多