四方显神

导航

解决bootstraptable只能初始化数据一次的问题

ajax+bootstraptable展示数据的时候,无法根据需求更改展示内容,报错:You cannot initialize the table more than once!

解决方案:

加一行代码,先将bootstraptable销毁

$("#tool1table").bootstrapTable('destroy');

<script>
    $("#tool1btn").click(function () {

        if ($("#tool1select_gene").val() == "" && $("#tool1select_disease").val() == "") {
            alert("Please select a dataset or gene name for analysis.")
        } else {
            $.ajax({
                type: 'POST',
                dataType: 'json',
                data: {
                    symbol: $("#tool1select_gene").val(),
                    disease: $("#tool1select_disease").val()
                },
                url: '/cuDB/analysis/differential/result',
                success: function (diff_return) {
                    const return_data = JSON.parse(JSON.stringify(diff_return));
                    $("#tool1table").bootstrapTable('destroy');
                    {#$("#tool1table").bootstrapTable('refresh'); //亲测重新刷新不可以,只能销毁 #}
                    $("#tool1table").bootstrapTable({
                        columns: [{
                            field: 'symbol',
                            title: 'Symbol',
                            sortable: true
                        }, {
                            field: 'disease',
                            title: 'Disease',
                            sortable: true
                        }, {
                            field: 'log_fc',
                            title: 'logFC',
                            sortable: true
                        }, {
                            field: 'p_value',
                            title: 'p value',
                            sortable: true
                        },
                            {
                                field: 'rid',
                                title: 'More<br>Details',
                                align: 'center',
                                {#formatter: detailFormatter,#}
                            },
                        ],
                        data: return_data,
                    });
                },
                error: function () {
                    console.log("出问题咯error")
                }
            });
        }
    });
</script>

 

posted on 2024-09-21 10:56  szdbjooo  阅读(90)  评论(0编辑  收藏  举报