为了账号安全,请及时绑定邮箱和手机立即绑定

Datatables.net 没有加载 JSON - SignalR

Datatables.net 没有加载 JSON - SignalR

C#
ABOUTYOU 2023-07-09 15:26:43
我想将以下 JSON 对象加载到 Datatables.net 中,但它不起作用。我使用 SignalR 将 JSON 从服务器端传递到客户端,并且它运行,因为我可以接收 JSON,但无法将其加载到数据表中。请问有人可以帮助我吗?提前致谢!C#代码:cmm_dbEntities db = new cmm_dbEntities();var result = from a in db.TAB_PNjoin b in db.TAB_APPL on a.idapplicability equals b.idapplicabilityjoin c in db.TAB_ISSUE on a.idissue equals c.idissueselect new{    a.pn,    a.title,    b.appl_desc,    c.issue,    c.issue_date,    c.rev,    c.rev_date,    a.equipment,    a.formattype};var obj = new { data = result };string json = JsonConvert.SerializeObject(obj);return json;这是我的 JSON:{    "data": [{        "pn": "346B0300A3300.801",        "title": "Test Bench Replenish Unit, Engine Oil - Operation and Maintenance Manual with Illustrated Parts Breakdown",        "appl_desc": "DESCRIZIONE 005",        "issue": "ISSUE-003",        "issue_date": "2015-03-01T00:00:00",        "rev": "0003",        "rev_date": "AAAAAAAAB9M=",        "equipment": "Test Bench, Replenish Unit, Engine Oil",        "formattype": "XML"    }, {        "pn": "346B0300A3300.805",        "title": "Test Bench Replenish Unit, Engine Oil - Operation and Maintenance Manual with Illustrated Parts Breakdown",        "appl_desc": "DESCRIZIONE 015",        "issue": "ISSUE-004",        "issue_date": "2015-04-01T00:00:00",        "rev": "004",        "rev_date": "AAAAAAAAB9Q=",        "equipment": "Test Bench, Replenish Unit, Engine Oil",        "formattype": "XML"    }, {        "pn": "415808",        "title": "Operating and Maintenance Manual for Ni-Cd Aircraft batteries",        "appl_desc": "DESCRIZIONE 015",        "issue": "ISSUE-001",        "issue_date": "2015-01-01T00:00:00",        "rev": "0001",        "rev_date": "AAAAAAAAB9E=",        "equipment": "Battery",        "formattype": "XML"    }, }
查看完整描述

2 回答

?
肥皂起泡泡

TA贡献1829条经验 获得超6个赞

我没有看到你设置属性data。请data: data在初始化表时进行赋值。


hub.client.inizializzaFiltri = function (data) {


    console.log(data);


    $('#PNTable').DataTable({

        data: data //you are missing this

        dataSrc: "objects",

        columns: [

            { data: null, defaultContent: '' },

            { data: 'pn' },

            { data: 'title' },

            { data: 'appl_desc' },

            { data: 'issue' },

            { data: 'issue_date' },

            { data: 'rev' },

            { data: 'rev_date' },

            { data: 'equipment' },

            { data: 'formattype' }],

        order: [[1, "asc"]],

        columnDefs: [

            {

                orderable: false,

                className: 'select-checkbox',

                targets: 0

            },

        ],

        retrieve: true,

        select: {

            style: 'os',

            selector: 'td:first-child'

        }

    });

}


查看完整回答
反对 回复 2023-07-09
?
萧十郎

TA贡献1815条经验 获得超13个赞

我是这样解决的...


C#代码:


    ...

    var obj = new { data = result };

    string json = JsonConvert.SerializeObject(obj);


    return json;

JS代码:


hub.client.inizializzaFiltri = function (data) {


    var jsn = JSON.parse(data);


    $('#PNTable').DataTable({

    "bPaginate": false,

    "bLengthChange": false,

    "bFilter": true,

    "bInfo": true,

    "bAutoWidth": true,

    "dataSrc": "",

    "data": jsn.data,

    "dataSrc": jsn.data,

     responsive: true,

     columns: [

        { "data": null, defaultContent: '' },

        { "data": 'pn' },

        { "data": 'title' },        

         ...

在将其放入数据表之前,我必须使用 JSON.parse(data) 反序列化 che JSON。


再次感谢


查看完整回答
反对 回复 2023-07-09
  • 2 回答
  • 0 关注
  • 116 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信