微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何在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 举报,一经查实,本站将立刻删除。