Javascript 添加新行时的DataTable警告消息

Javascript 添加新行时的DataTable警告消息,javascript,datatable,Javascript,Datatable,当我从表单提交结果并试图在结果保存后向datatable添加新行时,我从DataTables收到以下错误消息 DataTables警告:表id=付款-为第9行第2列请求了未知参数“paymentTypes.name”。有关此错误的详细信息,请参阅 这是我的数据表 <!-- .table --> <table id="payments" class="table table-bordered table-hover" cellspacing="0" widt

当我从表单提交结果并试图在结果保存后向datatable添加新行时,我从DataTables收到以下错误消息

DataTables警告:表id=付款-为第9行第2列请求了未知参数“paymentTypes.name”。有关此错误的详细信息,请参阅

这是我的数据表

   <!-- .table -->
        <table id="payments" class="table table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                                <tr>
                                                    <th>Date Created</th>
                                                    <th>Created By</th>
                                                    <th>Payment Type</th>
                                                    <th>Reference Number</th>
                                                    <th>Comment</th>
                                                    <th>Amount</th>
                                                    <th>Delete</th>
                                                </tr>
                                            </thead>
                                            <tbody></tbody>
                                        </table><!-- /.table -->
确实添加了行,但该列为空。见下文


经过数小时的研究,我找到了一种不同的方法来适应这种情况

$('#payments').append('<tr><td>' + responsedata.dateCreated + '</td><td>' + responsedata.createdBy + '</td><td>' + responsedata.paymentTypes.name + '</td><td>' + responsedata.referenceNumber + '</td><td>' + responsedata.comments + '</td><td>' + responsedata.amount + '</td><td>' + "<button class='btn-link js-delete' data-paymentdetails-id=" + responsedata.id + ">Delete</button>" + '</td></tr>');
$(“#付款”).append(“”+responsedata.dateCreated+“”+responsedata.createdBy+“”+responsedata.paymentTypes.name+“”+responsedata.referenceNumber+“”+responsedata.comments+“”+responsedata.amount+“”+Delete“+”);

尝试删除点,在列定义和添加行时使用数据:“paymentTypesName”。仍然会收到与DataTables相同的错误警告:表id=付款-请求第11行第2列的未知参数“paymentTypes.name”。有关此错误的详细信息,请参阅是否确实在任何地方都更改了它?当添加新行“paymentTypesName”:responsedata.paymentTypes.name时,如果我将该列名的原始加载更改为paymentTypesName,则它将在保存时加载该记录,但在初始加载之前所有记录的datatable时,它将失败,因为它需要点
            $.ajax({
                url: "/api/Payments",
                type: "POST",
                data: data,
                success: function (respText) {
                    responsedata = respText;
                    console.log(responsedata);
                    console.log(responsedata.dateCreated);
                    console.log(responsedata.paymentTypes.name);
                    console.log(responsedata.referenceNumber);
                    console.log(responsedata.comments);
                    console.log(responsedata.amount);
                    var paymentsTable2 = $('#payments').DataTable();

                    paymentsTable2.row.add( {
                                        "dateCreated":   responsedata.dateCreated,
                                        "createdBy":   responsedata.createdBy,
                                        "paymentTypes.name": responsedata.paymentTypes.name,
                                        "referenceNumber": responsedata.referenceNumber,
                                        "comments":     responsedata.comments,
                                        "amount": responsedata.amount,
                                        "id":       responsedata.id
                    }).draw( false );

                    toastr.success("Payment successfully recorded.");

                },
                error: function () {
                    toastr.error("Something unexpected happened.");
                }
            });
$('#payments').append('<tr><td>' + responsedata.dateCreated + '</td><td>' + responsedata.createdBy + '</td><td>' + responsedata.paymentTypes.name + '</td><td>' + responsedata.referenceNumber + '</td><td>' + responsedata.comments + '</td><td>' + responsedata.amount + '</td><td>' + "<button class='btn-link js-delete' data-paymentdetails-id=" + responsedata.id + ">Delete</button>" + '</td></tr>');