如何在 backbone.js 中动态使用 bootstrap mergeCells

how to use bootstrap mergeCells dynamically in backbone.js

我有一个创建 bootstrap table 的函数,我必须动态合并 table 中的特定列。

 this.$('#Table1').bootstrapTable({
        striped: false,
        minimumCountColumns: 2,
        smartDisplay:true,
        clickToSelect: false,
        columns:[
             {
                field:'Key2',
                title: $.t('report:'+code+'.Col2'),
                align: 'left',
                valign: 'middle', 
                sortable: true,
                events : this.linkEvents
                formatter :this.linkFormatter
             }
        ]
     });

linkEvent 函数:

linkEvents: {
        'onPostBody #Table1': function(e,value,row,index) {
        console.log("Inside post-body event");
        $('#Table1').bootstrapTable('mergeCells',{
        index:6,
        colspan:2
        });
        }
        }

即使上面的代码不起作用,它也没有进入 mergeCells 方法。请帮我解决这个问题..

终于在@Frogmouth的帮助下找到了答案(真的很支持).. 更改代码如下:

var keys=[];
this.$('#Table1').bootstrapTable({
        striped: false,
        minimumCountColumns: 2,
        smartDisplay:true,
        clickToSelect: false,
        columns:[
             {
                field:'Key2',
                title: $.t('report:'+code+'.Col2'),
                align: 'left',
                valign: 'middle', 
                sortable: true,
                formatter :function(value, row, index){
                           var rowValue = row.Data.Key2;
                           if(rowValue.trim()==''){ // if column value is empty those columns have to be merged
                            keys.push(index);
                           }                        
                           return row.Data.detailIndKey2;
                           }
             }
        ]
     });

//不需要linkEvents函数。而是使用 jquery

$(function () { 
$('#Table1').on('post-body.bs.table', function (e, data) {
for(var i=0;i<keys.length;i++){
$('#Table1').bootstrapTable('mergeCells',{
index:keys[i], //for dynamic keys
field:'Key1',
colspan:4 // how many columns have to be merged.
});
}
}); 
});

谢谢