0

我无法让我的 Kendo TreeList 绑定到我的数据。

模型

public class Test
    {
        public int EmployeeId { get; set; }
        public string Name { get; set; }
        public string ReportsTo { get; set; }            
    }

控制器

[HttpPost]
    public JsonResult GetAllTest([DataSourceRequest] DataSourceRequest request)
    {
        var result = GetTest().ToTreeDataSourceResult(request,
                //e => e.EmployeeId,
                e => e.Name,
                e => e.ReportsTo,
                e => e);
        return Json(result, JsonRequestBehavior.AllowGet);
    }

    public IEnumerable<Models.InvoiceModels.Test> GetTest()
    {
        var invoiceList = new List<Models.InvoiceModels.Test>();
        var invoice0 = new Models.InvoiceModels.Test();

        invoice0.EmployeeId = 1;
        invoice0.Name = "K S";
        invoice0.ReportsTo = null;            

        invoiceList.Add(invoice0);

        var invoice1 = new Models.InvoiceModels.Test();

        invoice1.EmployeeId = 2;
        invoice1.Name = "O G";
        //invoice1.ReportsTo = 1;
        invoice1.ReportsTo = "K S";                        

        invoiceList.Add(invoice1);

        var invoice2 = new Models.InvoiceModels.Test();

        invoice2.EmployeeId = 3;
        invoice2.Name = "T N";
        //invoice2.ReportsTo = 1;
        invoice2.ReportsTo = "K S";                        

        invoiceList.Add(invoice2);

        var invoice3 = new Models.InvoiceModels.Test();

        invoice3.EmployeeId = 4;
        invoice3.Name = "E L";
        //invoice3.ReportsTo = 1;
        invoice3.ReportsTo = "K S";                        

        invoiceList.Add(invoice3);

        var invoice4 = new Models.InvoiceModels.Test();

        invoice4.EmployeeId = 5;
        invoice4.Name = "T C";
        //invoice4.ReportsTo = 4;            
        invoice4.ReportsTo = "E L";


        invoiceList.Add(invoice4);

        var invoice6 = new Models.InvoiceModels.Test();

        invoice6.EmployeeId = 6;
        invoice6.Name = "J B";
        //invoice6.ReportsTo = 4;
        invoice6.ReportsTo = "E L";            

        invoiceList.Add(invoice6);

        return invoiceList;
    }

看法

@{Html.Kendo().TreeList<COOP_MVC_Test.Models.InvoiceModels.Test>()
            .Name("treelist")
            .Columns(columns =>
            {
                columns.Add().Field(p => p.Name).Title("Name").Width("150px");                                     
                columns.Add().Field(p => p.EmployeeId).Title("ID").Width("50px");                                        
            }
        )
        .Filterable()
        .Sortable()
        .HtmlAttributes(new { style = "height: 700px; width: 99.8%" })                        
        .DataSource(DataSource => DataSource                
            .Read(read => read.Action("GetAllTest", "Home"))
            .ServerOperation(false)                
            .Model(model =>
            {
                model.Id(p => p.Name);
                model.ParentId(p => p.ReportsTo);
                //model.Field(p => p.Name);
                //model.Field(p => p.ReportsTo);
            }
            )
        )
        .Height(650)
        .Render();
    }

传递的数据

{"Data":[
        {"EmployeeId":1,"Name":"K S","ReportsTo":null}
        ,{"EmployeeId":2,"Name":"O G","ReportsTo":"K S"}
        ,{"EmployeeId":3,"Name":"T N","ReportsTo":"K S"}
        ,{"EmployeeId":4,"Name":"E L","ReportsTo":"K S"}
        ,{"EmployeeId":5,"Name":"T C","ReportsTo":"E L"}
        ,{"EmployeeId":6,"Name":"J B","ReportsTo":"E L"}
    ] "AggregateResults":{} ,"Errors":null}

这在我使用 EmployeeId 时有效,它是一个 INT 数据类型。但是,当我将 Name 更改为父 ID 并将 ReportsTo 更改为字符串类型时,它返回“没有要显示的记录”。

我错过了什么吗?似乎无法为我的一生弄清楚。

4

0 回答 0