【问题标题】:Displaying Json Data on DataTables在 DataTables 上显示 Json 数据
【发布时间】:2016-04-06 15:33:07
【问题描述】:

我正在尝试在我的数据表中显示一些硬编码数据,但由于某种原因它没有显示任何内容。我有以下代码:

js 文件

financialTargetData = [
    {"FirstName": 'Dan',
    "UserId": "1",
    "Sex": 'Male'},
    {"FirstName": "Peter",
     "UserId": "2",
     "Sex": "Male"}
];

attached()
{
    var that = this;
    $('#financialtargettable').DataTable({
        "data": that.financialTargetData,
        "lengthMenu": [[12, 24, 36, -1], [12, 24, 36, "All"]],
        "paging": true
    });
}

html 文件

<template>
<div class="container-fluid">
    <div class="row">

        <div class="col-sm-12">
            <h2>Financial Targets</h2>

            <div class="box">
                <div class="box-header">
                    <h3 class="box-title">Data Table With Full Features</h3>
                </div><!-- /.box-header -->
                <div class="box-body">
                    <table id="financialtargettable" class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>FirstName</th>
                                <th>UserId</th>
                                <th>Sex</th>
                                <!--<th>GrossWorkingDays</th>-->
                                <!--<th>NetWorkingDays</th>-->
                            </tr>
                        </thead>
                    </table>
                </div><!-- /.box-body -->
            </div><!-- /.box -->

        </div>

    </div>
</div>

我正在使用带有 Aurelia 框架的 javascript ES6。不知道要提供什么更多信息,但这并没有给我任何错误,我只是不知道发生了什么......

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: javascript html json datatables


    【解决方案1】:

    尝试将您的数据调整为如下所示:

    financialTargetData = [
        ['Dan', 1, 'Male'],
        ["Peter", "2", "Male"]
    ];
    

    这是一个工作示例:http://plnkr.co/edit/1Aj3P7Lzr8HPBY7P5OKj?p=preview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 2018-10-22
      • 2015-12-08
      • 2019-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多