Kendo网格错误:kendo.all.min.js:12 Uncaught TypeError:e.slice不是函数

时间:2015-10-14 14:41:54

标签: javascript json ajax asp.net-mvc kendo-grid

我有一个kendo网格,它使用javascript中的ajax绑定其数据源,如下所示:

Kendogrid:

@(Html.Kendo().Grid<WEB02.ConfigurationModel.ActivityGridDetails>()
.Name("Activitydet")
.Columns(columns =>
{
    columns.Bound(o => o.Id).Width(40);
    columns.Bound(o => o.Config).Width(200);
    columns.Bound(o => o.Status).Width(250);
    columns.Bound(o => o.In).Width(250);
    columns.Bound(o => o.Out).Width(250);




})
.DataSource(dataSource => dataSource
    .Ajax()
    .Events(events => events.Error("error_handler"))
     .Model(model => model.Id(p => p.Id))
    )
)
)

使用Javascript:

function onChange(e) {
    var grid = $("#grid").data("kendoGrid");
    var dataRows = grid.items();
    var rowIndex = dataRows.index(grid.select());
    var selectedname = grid.dataItems()[rowIndex];
    console.log("aly" + selectedname.NodeId);
    document.getElementById("ActivityGrid").style.bottom = "100px";



    $.ajax({

        type: 'POST',
        url: '/Configuration/ActivityGridDisplay/',
        dataType: 'json',
        data: { nodeName: selectedname.Name, nodeType: selectedname.Type, nodeID: selectedname.NodeId },
        success: function (result) {

            $("#Activitydet").data("kendoGrid").dataSource.data(result);
            //$("#Activitydet").data("kendoGrid").dataSource.fetch();
        }
    })}

控制器:

public ActionResult ActivityGridDisplay([DataSourceRequest] DataSourceRequest request, string nodeName, string nodeType, string nodeID)

    {



        ActivityGrid Activity = new ActivityGrid();
        Activity.Grid = new DataTable();

        string rep = "ns=2;s=";
        nodeID = nodeID.Replace(rep, "");

        string nodeConfig= nodeID+".CONFIG";
        string nodeStatus= nodeID+".STATUS";
        string nodeIN= nodeID+".IN";
        string nodeOUT= nodeID+".OUT";
        Dictionary<string, string> ActivityConfig = RxMUaClient.DetailsBrowse("2", "127.0.0.1:48030", nodeConfig);
        Dictionary<string, string> ActivityStatus = RxMUaClient.DetailsBrowse("2", "127.0.0.1:48030", nodeStatus);
        Dictionary<string, string> ActivityIN = RxMUaClient.DetailsBrowse("2", "127.0.0.1:48030", nodeIN);
        Dictionary<string, string> ActivityOUT = RxMUaClient.DetailsBrowse("2", "127.0.0.1:48030", nodeOUT);


        List<Dictionary<string, string>> Collection = new  List<Dictionary<string, string>>();
        Collection.Add(ActivityConfig);
        Collection.Add(ActivityStatus);
        Collection.Add(ActivityIN);
        Collection.Add(ActivityOUT);

        int max =Collection[0].Count;
        for (int CC = 1; CC < 4; CC++)
        {

            if (Collection[CC].Count > max)
            {
                max = Collection[CC].Count;
            }
        }
        DataTable Table = new DataTable();
        Table.Columns.Add("Id");
        Table.Columns.Add("Config");
        Table.Columns.Add("Status");
        Table.Columns.Add("In");
        Table.Columns.Add("Out");
        for (int i = 0; i <= max; i++)
        {
            DataRow newRow = Table.NewRow();
            newRow[0] = i;

            int l=1;
                foreach (Dictionary<string, string> e in Collection)
                {

                    if (i < e.Count)
                    {
                        var element = e.ElementAt(i);
                        newRow[l] = element.Value;
                    }
                    l++;

                }
                Table.Rows.Add(newRow);

        }



        if (request.Aggregates.Any())
        {
            request.Aggregates.Each(agg => agg.Aggregates.Each(a =>
            {
                a.MemberType = Table.Columns[agg.Member].DataType;
            }));
        }
        return Json(Table.ToDataSourceResult(request));

}

我之前使用模型完成了相同的网格,但直接使用了kendo网格中的read函数,它曾经没有问题。这次使用ajax绑定读取不起作用,因为它给出了这个错误: kendo.all.min.js:12 Uncaught TypeError:e.slice不是函数

我试图将allowget放到json调用但没有解决它,我之前没有设置模型ID,所以我设置了一个并没有解决它。我试图从kendo网格中删除数据源部分,但没有这样做。有什么建议??

2 个答案:

答案 0 :(得分:2)

发现问题:它是在javascript部分中传递整个数据,而只传递数据数组部分:

要更改的ajax函数如下:

 $.ajax({

        type: 'POST',
        url: '/Configuration/ActivityGridDisplay/',
        dataType: 'json',
        data: { nodeName: selectedname.Name, nodeType: selectedname.Type, nodeID: selectedname.NodeId },
        success: function (result) {
            console.log(result);
            var pass = result.Data;
            $("#Activitydet").data("kendoGrid").dataSource.data(pass);
            //$("#Activitydet").data("kendoGrid").dataSource.fetch();
        }
    })

答案 1 :(得分:0)

使用$(&#34; #grid&#34;)。kendoGrid得到同样的问题并通过放置&#39;数据&#39;来解决它。控制器中的属性。 例如:            返回Json(results.Data,JsonRequestBehavior.AllowGet);