如何在MVC中根据运行时的数据表侦听器生成数据表行

问题描述

我想在运行时生成数据表的标头,然后我想填充行,但是我找不到很好的资源来处理此问题。

我这样尝试过:

  <script>
        $(document).ready(function () {
            $('#example').DataTable(
                {
                    "processing": true,"serverSide": true,"ajax": {
                        "url": "/Admin/GetList","type": "Get","datatype": "json","dataSrc": function (json) {
                            debugger;
                            jsonObjc = json.data;
                            return jsonObjc;
                        },},"columnDefs": [{ "defaultContent": "-","targets": "_all" }],"bDestroy": true
            });
        });
    </script>

实际上我创建了以下标题

<table id="example" class="table table-striped table-bordered" style="width:100%">
    <thead>
        <tr>
    
            @foreach (var campaingId in Model.Rapors.Campains)
            {
                <th>@campaingId.CampaignId</th>
            }

        </tr>
    </thead>
</table>

问题是我无法填充行,因为我不知道数据表有多少个头并且我必须生成与数据表头的数量一样多的行对象

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)