将数据源设置为 kendo 网格时获取错误消息 e.slice 不是函数
Getting error message e.slice is not a function while setting data source to kendo grid
我正在尝试获取数据并将该数据设置为使用 ajax 的 kendo 网格的数据源。
我正在从控制器正确获取数据。但是当我尝试将数据源设置为 kendo 网格时,它显示以下错误:
Uncaught TypeError: e.slice is not a function
$(function () {
loadCstDetails();
});
function loadCstDetails() {
var statemenetInquiryParameter = {};
statemenetInquiryParameter.isPrintZero = true;
statemenetInquiryParameter.isPrintPayments = true;
statemenetInquiryParameter.isPrintAdjust = true;
statemenetInquiryParameter.cst_stmt_from = new Date("April 01, 2016");
statemenetInquiryParameter.cst_stmt_to = new Date("April 12, 2016");
statemenetInquiryParameter.customerCode = 007;
$.ajax({
type: 'POST',
data: JSON.stringify({ statemenetInquiryParameter: statemenetInquiryParameter }),
contentType: 'application/json;',
dataType: 'json',
url: '@Url.Action("LoadCustomerStatementEnquiryDetails", "Stage")',
success: function (result) {
$('#gridCustomerCstTranDetailsManual').data('kendoGrid').dataSource.data(result);
}
});
}
<div class="row" style="margin-top: 5px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
@(Html.Kendo().Grid<ServicePROWeb.ServiceProWCFService.CstTran>()
.Name("gridCustomerCstTranDetailsManual")
.Columns(columns =>
{
columns.Bound(p => p.cst_inv_date).Title("Invoice Date").HtmlAttributes(new { @style = "text-align: right;" }).Format(Session["DisplayFormat_GridDate"].ToString()).Width(80);
columns.Bound(p => p.cst_type).Title("Type").Width(80);
columns.Bound(p => p.cst_ih_invno).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Invoice Number").Width(80);
columns.Bound(p => p.cst_dr_amount).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Debit").Width(80);
columns.Bound(p => p.cst_cr_amount).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Credit").Width(80);
columns.Bound(p => p.cst_dr_balance).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Balance").Width(80);
})
.Selectable()
.Sortable()
.Scrollable()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "cursor:pointer;height:auto;width:auto;margin-top: 0px;" })
.DataSource(dataSource => dataSource.Ajax())
)
</div>
</div>
public class StatemenetInquiryParameter
{
public decimal customerCode { get; set; }
public DateTime cst_stmt_from { get; set; }
public DateTime cst_stmt_to { get; set; }
public bool isPrintZero { get; set; }
public bool isPrintPayments { get; set; }
public bool isPrintAdjust { get; set; }
}
public JsonResult LoadCustomerStatementEnquiryDetails([DataSourceRequest]DataSourceRequest request, StatemenetInquiryParameter statemenetInquiryParameter)
{
List<CstTran> l = new List<CstTran>();
for (int i = 0; i < 12; i++)
{
CstTran c = new CstTran();
c.cst_inv_date = statemenetInquiryParameter.cst_stmt_from.AddDays(i);
c.cst_type = "I";
c.cst_ih_invno = i + 1;
c.cst_dr_amount = i;
c.cst_cr_amount = 0;
c.cst_dr_balance = c.cst_dr_balance + i;
l.Add(c);
}
return Json(l.ToDataSourceResult(request));
}
public class CstTran
{
public decimal cst_cm_code { get; set; }
public string cst_type { get; set; }
public DateTime cst_stmt_from { get; set; }
public int cst_ih_invno { get; set; }
public int cst_rcpt_no { get; set; }
public decimal cst_dr_amount { get; set; }
public decimal cst_cr_amount { get; set; }
public DateTime cst_inv_date { get; set; }
public DateTime cst_stmt_to { get; set; }
public decimal cst_dr_balance { get; set; }
public int cst_ih_acct_per { get; set; }
public int cst_lvl4_sequence { get; set; }
}
仅从提供的代码的目视检查来看,我怀疑我们这里有两件事。
首先:
.DataSource(dataSource => dataSource.Ajax())
如果您正在定义一个 "remote" 数据源,那么您需要为命令提供一个 read 操作或将其绑定到一个集合(根据我的经验)可能是导致您遇到的错误的原因。
除此之外,您似乎正在编写网格声明可以为您完成的代码。
如果您希望将一些参数发送到控制器,那么我建议您按如下方式更改您的代码:
.DataSource(dataSource => {
dataSource.Ajax()
.Read(read => {
read.Action("LoadCustomerStatementEnquiryDetails", "Stage").Data("loadCstDetails");
})
然后将现有的 loadCstDetails 函数更改为:
function loadCstDetails() {
var statemenetInquiryParameter = {};
statemenetInquiryParameter.isPrintZero = true;
statemenetInquiryParameter.isPrintPayments = true;
statemenetInquiryParameter.isPrintAdjust = true;
statemenetInquiryParameter.cst_stmt_from = new Date("April 01, 2016");
statemenetInquiryParameter.cst_stmt_to = new Date("April 12, 2016");
statemenetInquiryParameter.customerCode = 007;
return {statemenetInquiryParameter: statemenetInquiryParameter};
}
这应该会像您原来那样传递对象。
希望这能为您提供可行的解决方案。
这个错误是由于使用ToDataSourceResult()
造成的。尝试更新 LoadCustomerStatementEnquiryDetails()
方法,如下所示:
public JsonResult LoadCustomerStatementEnquiryDetails(StatemenetInquiryParameter statemenetInquiryParameter)
{
List<CstTran> l = new List<CstTran>();
for (int i = 0; i < 12; i++)
{
CstTran c = new CstTran();
c.cst_inv_date = statemenetInquiryParameter.cst_stmt_from.AddDays(i);
c.cst_type = "I";
c.cst_ih_invno = i + 1;
c.cst_dr_amount = i;
c.cst_cr_amount = 0;
c.cst_dr_balance = c.cst_dr_balance + i;
l.Add(c);
}
return Json(l, JsonRequestBehavior.AllowGet);
}
Hıpe 这有助于...
我正在尝试获取数据并将该数据设置为使用 ajax 的 kendo 网格的数据源。
我正在从控制器正确获取数据。但是当我尝试将数据源设置为 kendo 网格时,它显示以下错误:
Uncaught TypeError: e.slice is not a function
$(function () {
loadCstDetails();
});
function loadCstDetails() {
var statemenetInquiryParameter = {};
statemenetInquiryParameter.isPrintZero = true;
statemenetInquiryParameter.isPrintPayments = true;
statemenetInquiryParameter.isPrintAdjust = true;
statemenetInquiryParameter.cst_stmt_from = new Date("April 01, 2016");
statemenetInquiryParameter.cst_stmt_to = new Date("April 12, 2016");
statemenetInquiryParameter.customerCode = 007;
$.ajax({
type: 'POST',
data: JSON.stringify({ statemenetInquiryParameter: statemenetInquiryParameter }),
contentType: 'application/json;',
dataType: 'json',
url: '@Url.Action("LoadCustomerStatementEnquiryDetails", "Stage")',
success: function (result) {
$('#gridCustomerCstTranDetailsManual').data('kendoGrid').dataSource.data(result);
}
});
}
<div class="row" style="margin-top: 5px;">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
@(Html.Kendo().Grid<ServicePROWeb.ServiceProWCFService.CstTran>()
.Name("gridCustomerCstTranDetailsManual")
.Columns(columns =>
{
columns.Bound(p => p.cst_inv_date).Title("Invoice Date").HtmlAttributes(new { @style = "text-align: right;" }).Format(Session["DisplayFormat_GridDate"].ToString()).Width(80);
columns.Bound(p => p.cst_type).Title("Type").Width(80);
columns.Bound(p => p.cst_ih_invno).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Invoice Number").Width(80);
columns.Bound(p => p.cst_dr_amount).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Debit").Width(80);
columns.Bound(p => p.cst_cr_amount).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Credit").Width(80);
columns.Bound(p => p.cst_dr_balance).Format("{0:n2}").HtmlAttributes(new { @style = "text-align: right;" }).Filterable(false).Title("Balance").Width(80);
})
.Selectable()
.Sortable()
.Scrollable()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "cursor:pointer;height:auto;width:auto;margin-top: 0px;" })
.DataSource(dataSource => dataSource.Ajax())
)
</div>
</div>
public class StatemenetInquiryParameter
{
public decimal customerCode { get; set; }
public DateTime cst_stmt_from { get; set; }
public DateTime cst_stmt_to { get; set; }
public bool isPrintZero { get; set; }
public bool isPrintPayments { get; set; }
public bool isPrintAdjust { get; set; }
}
public JsonResult LoadCustomerStatementEnquiryDetails([DataSourceRequest]DataSourceRequest request, StatemenetInquiryParameter statemenetInquiryParameter)
{
List<CstTran> l = new List<CstTran>();
for (int i = 0; i < 12; i++)
{
CstTran c = new CstTran();
c.cst_inv_date = statemenetInquiryParameter.cst_stmt_from.AddDays(i);
c.cst_type = "I";
c.cst_ih_invno = i + 1;
c.cst_dr_amount = i;
c.cst_cr_amount = 0;
c.cst_dr_balance = c.cst_dr_balance + i;
l.Add(c);
}
return Json(l.ToDataSourceResult(request));
}
public class CstTran
{
public decimal cst_cm_code { get; set; }
public string cst_type { get; set; }
public DateTime cst_stmt_from { get; set; }
public int cst_ih_invno { get; set; }
public int cst_rcpt_no { get; set; }
public decimal cst_dr_amount { get; set; }
public decimal cst_cr_amount { get; set; }
public DateTime cst_inv_date { get; set; }
public DateTime cst_stmt_to { get; set; }
public decimal cst_dr_balance { get; set; }
public int cst_ih_acct_per { get; set; }
public int cst_lvl4_sequence { get; set; }
}
仅从提供的代码的目视检查来看,我怀疑我们这里有两件事。
首先:
.DataSource(dataSource => dataSource.Ajax())
如果您正在定义一个 "remote" 数据源,那么您需要为命令提供一个 read 操作或将其绑定到一个集合(根据我的经验)可能是导致您遇到的错误的原因。
除此之外,您似乎正在编写网格声明可以为您完成的代码。
如果您希望将一些参数发送到控制器,那么我建议您按如下方式更改您的代码:
.DataSource(dataSource => {
dataSource.Ajax()
.Read(read => {
read.Action("LoadCustomerStatementEnquiryDetails", "Stage").Data("loadCstDetails");
})
然后将现有的 loadCstDetails 函数更改为:
function loadCstDetails() {
var statemenetInquiryParameter = {};
statemenetInquiryParameter.isPrintZero = true;
statemenetInquiryParameter.isPrintPayments = true;
statemenetInquiryParameter.isPrintAdjust = true;
statemenetInquiryParameter.cst_stmt_from = new Date("April 01, 2016");
statemenetInquiryParameter.cst_stmt_to = new Date("April 12, 2016");
statemenetInquiryParameter.customerCode = 007;
return {statemenetInquiryParameter: statemenetInquiryParameter};
}
这应该会像您原来那样传递对象。
希望这能为您提供可行的解决方案。
这个错误是由于使用ToDataSourceResult()
造成的。尝试更新 LoadCustomerStatementEnquiryDetails()
方法,如下所示:
public JsonResult LoadCustomerStatementEnquiryDetails(StatemenetInquiryParameter statemenetInquiryParameter)
{
List<CstTran> l = new List<CstTran>();
for (int i = 0; i < 12; i++)
{
CstTran c = new CstTran();
c.cst_inv_date = statemenetInquiryParameter.cst_stmt_from.AddDays(i);
c.cst_type = "I";
c.cst_ih_invno = i + 1;
c.cst_dr_amount = i;
c.cst_cr_amount = 0;
c.cst_dr_balance = c.cst_dr_balance + i;
l.Add(c);
}
return Json(l, JsonRequestBehavior.AllowGet);
}
Hıpe 这有助于...