DataTable表中没有数据可用

时间:2016-11-16 11:30:14

标签: javascript meteor datatables

我正在使用Meteor,我正在尝试使用此代码显示数据表。

我的JS:

onRendered() {

    $('#tableCarsWorkflow').DataTable({

        paging: true,
        searching: true,
        info: false,
        data: this.CarsList(),
        ordering: false,

        columns:
            [
     { data: "declaration.sg_art.numeroarticle", title: "Numéro de l'article" },
    { data: "declaration.sg_dec.quittance", title: "Quittance" },
    { data: "declaration.sg_art.bl", title: "Référence du BL" },
    { data: "declaration.sg_art.regime", title: "Régime douanier déclaré" },
    { data: "declaration.sg_art.nomenclature", title: "Nomenclature" },
    { data: "declaration.sg_art.description", title: "Description" },
    { data: "declaration.sg_art.num_colis", title: "Marque et numéro de châssis" },
    { data: "declaration.sg_art.Valeur_en_douane", title: "Valeur en douane" },
    { data: "declaration.sg_art.Pays_origine", title: "Pays d'origine" },
            ]
    });

    this.bindCarsListCLick();

},
bindCarsListCLick() {
    let self = this;

    $("#tableCarsWorkflow tr").bind("click", function (event) {
        console.log("click fired...")
        var dataTable = $(event.target).closest('table').DataTable();
        var row = dataTable.row(event.currentTarget);
        var rowData = row.data();

        if (!rowData) return; // Won't be data if a placeholder row is clicked

        $("#tableCarsWorkflow tr").removeClass('selected');
        $(this).addClass('selected');
        self.showDetails(true)

        self.workflowTable(_.where(self.WorkflowList(), { CarId: rowData._id }))


});

Html:

<template name="carWorkFlow">
    <div class="row">
        <div class="col-sm-12">
            <div class="card-box">
                <h4>Liste des véhicules</h4>
                <table id="tableCarsWorkflow" class="table table-condensed table-bordered fixed-table-body"></table>
            </div>
        </div>
    </div>
</template>

但是当我第一次加载页面时,我总是得到相同的消息: “表中没有数据。”

2 个答案:

答案 0 :(得分:0)

尝试数据:CarsList()。find()。fetch()

答案 1 :(得分:0)

你确定你的this.CarsList()正在返回信息吗? 在onRendered的第一行放置一个console.log进行调试

onRendered() {
 console.log(this.CarsList());
 ...
}
祝你好运!