Javascript DataTables警告-请求未知参数';0';对于第0行,第0列
我使用jQuery数据表来显示使用存储过程和web服务从数据库中获取的数据。我可以使用Fiddler很好地运行SP或服务,但在填充数据表时,我会记录错误。在我的具体案例中,信息是: DataTables警告:表id=TBLCASHERCORD-为第0行第0列请求的未知参数“0” 然后发生的情况是,我的DataTable显示了正确的行数,但所有单元格都是空的 我很确定HTML表中的列数与我使用aoColumns时要推的列数相同(四列),但我可能错了。我知道有很多相同的问题被问到,但这是唯一一个我觉得有用的可能相关的问题,我也尝试过,但没有成功 我的HTML表格:Javascript DataTables警告-请求未知参数';0';对于第0行,第0列,javascript,c#,jquery,datatables,Javascript,C#,Jquery,Datatables,我使用jQuery数据表来显示使用存储过程和web服务从数据库中获取的数据。我可以使用Fiddler很好地运行SP或服务,但在填充数据表时,我会记录错误。在我的具体案例中,信息是: DataTables警告:表id=TBLCASHERCORD-为第0行第0列请求的未知参数“0” 然后发生的情况是,我的DataTable显示了正确的行数,但所有单元格都是空的 我很确定HTML表中的列数与我使用aoColumns时要推的列数相同(四列),但我可能错了。我知道有很多相同的问题被问到,但这是唯一一个我觉
<table id="tblCashRecord" class="table table-bordered">
<thead>
<tr>
<th>Kiosk Name</th>
<th>Service Type</th>
<th>Transaction Timestamp</th>
<th>Amount (RM)</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<th colspan="3" style="text-align: right">Total:</th>
<th><span id="totalAmount" style="margin-left: -8px;"></span></th>
</tr>
</tfoot>
</table>
我的web服务:
cashPaymentResponse IReport.GetCashPaymentRecord(string session, string reference, cashPaymentRequest request)
{
Guid sessionID, referenceID, kioskID;
Guid.TryParse(session, out sessionID);
Guid.TryParse(reference, out referenceID);
Guid.TryParse(request.kioskID, out kioskID);
if (sessionID == Guid.Empty)
{
return new cashPaymentResponse("Invalid Session.");
}
DateTime startDate, endDate;
try
{
startDate = new DateTime(Convert.ToInt32(request.startDate.Substring(6, 4)), Convert.ToInt32(request.startDate.Substring(3, 2)), Convert.ToInt32(request.startDate.Substring(0, 2)), 0, 0, 0);
endDate = new DateTime(Convert.ToInt32(request.endDate.Substring(6, 4)), Convert.ToInt32(request.endDate.Substring(3, 2)), Convert.ToInt32(request.endDate.Substring(0, 2)), 23, 59, 59);
}
catch (Exception ex)
{
return new cashPaymentResponse("No Date Selected.");
}
List<ReportCashPaymentRecord_Result> result;
try
{
using (MyDBEntities context = new MyDBEntities())
{
result = context.ReportCashPaymentRecord(sessionID, kioskID, startDate, endDate).ToList();
}
}
catch (Exception ex)
{
if (isDebug() == false)
{
return new cashPaymentResponse("Database connection failed.");
}
else
{
return new cashPaymentResponse(ex.Message);
}
}
if (result.Count > 0)
{
cashPaymentResponse response = new cashPaymentResponse();
cashPaymentItem item;
response.cashPayment = new List<cashPaymentItem>();
for (int i = 0; i < result.Count; i++)
{
item = new cashPaymentItem();
if (result[i].kioskName == "session")
{
return new cashPaymentResponse("Invalid Session.");
}
else
{
item.id = (Guid)result[i].cashID;
item.paymentRecordID = (Guid)result[i].paymentRecordID;
item.total = (decimal)result[i].total;
item.transactionTimestamp = JsonConvert.SerializeObject(new DateTime(result[i].transactiontimestamp.Value.Year, result[i].transactiontimestamp.Value.Month, result[i].transactiontimestamp.Value.Day, result[i].transactiontimestamp.Value.Hour, result[i].transactiontimestamp.Value.Minute, result[i].transactiontimestamp.Value.Second, 0, DateTimeKind.Utc)).Replace("\"", "");
item.kioskName = result[i].kioskName;
item.serviceType = (result[i].serviceType.ToString() == "0") ? "Assessment" : (result[i].serviceType.ToString() == "1") ? "Water Bill" : (result[i].serviceType.ToString() == "2") ? "Rental" : (result[i].serviceType.ToString() == "3") ? "Compound" : "None";
item.paymentType = (result[i].paymentType.ToString() == "1") ? "Cash" : (result[i].paymentType.ToString() == "3") ? "Credit Card" : (result[i].paymentType.ToString() == "2") ? "Cheque" : "None";
response.cashPayment.Add(item);
}
}
return response;
}
else
{
return new cashPaymentResponse();
}
}
编辑:我在上面的回复中编辑了guid以删除敏感信息。典型的匈牙利符号输入错误<对于arrayo对象,code>aaColumns应为
aoColumns
。那么我相信它会起作用的aoColumns
是1.10.x中的BTW,现在称为columns
(但仍然支持这两个名称)
通常,使用新的1.10.x camelcase命名约定,请跳过所有关于文字名称的问题:
table = $('#tblCashRecord').DataTable({
paging: false,
ordering: false,
autoWidth: false,
sortable: false,
filter: false,
info: false,
dom: 'Blfrtip',
data: data.aaData,
columns: [
{ data: "kioskName" },
{ data: "serviceType" },
{ data: "transactionTimestamp" },
{ data: "total" }
]
});
根据评论更新。更正“
aaColumn
”后,出现空单元格的原因是您使用了$。每个的方式都不正确:
$.each(response.cashPayment, function (item) {
应该是
$.each(response.cashPayment, function (index, item) { //<----
data.aaData.push({
"id": item.id,
$。每个(响应。现金支付,功能(索引,项目){//谢谢你的建议,我已经将aaColumns编辑为aoColumns,但仍然会出现相同的错误,只是现在transactionTimestamp列被填满了,所有这些都是当前日期时间,而不是它们应该具有的日期时间。我还将aoColumns更改为columns,将mData更改为data,没有任何更改。@Alycus,请参阅更新-您使用的是$。每个
都是错误的。就是这样,我没有想到要将索引传递到$。每个。非常感谢。
$.each(response.cashPayment, function (item) {
$.each(response.cashPayment, function (index, item) { //<----
data.aaData.push({
"id": item.id,