什么应该是提供给剑道树的数据格式?

时间:2013-08-30 05:25:12

标签: asp.net-mvc-3 kendo-ui kendo-treeview

我正在尝试构建一个剑道树菜单。我无法弄清楚数据应该以什么格式提供给窗口小部件。到目前为止我试过这个:

型号:

public class TreeModel
{
    public int ID { get; set; }
    public string Name { get; set; }
    public string URL { get; set; }
    public int? ParentsID { get; set; }
    public bool HasChild { get; set; }
}

控制器:

public ActionResult LoadMenu()
    {
       List<TreeModel> list = new List<TreeModel> {
       new TreeModel() { ID=1, Name="Setup", URL="m.facebook.com", HasChild=true},
       new TreeModel() { ID=10, Name="Leave", URL="google.com", ParentsID=1, HasChild=false},
       new TreeModel() { ID=2, Name="EmployeeInfo", URL="m.facebook.com", HasChild=true},
       new TreeModel() { ID=11, Name="Basic Employee", URL="m.facebook.com", HasChild=false, ParentsID=2},

       };

       var nodes = (from n in list
                    where n.HasChild == true
                    select n).ToList();

       return Json(nodes, JsonRequestBehavior.AllowGet);

    }

我的观点:

<script type="text/javascript">

    homogeneous = new kendo.data.HierarchicalDataSource({
        transport: {
            read: {
                url: "/Home/LoadMenu",
                //dataType: "json",
                type: "GET"

            }
        },
        schema: {
            model: {
                id: "ID",
                hasChildren: "HasChild"
            }
        }
    });




    $(document).ready(function () {

        $("#treeMenu").kendoTreeView({
            dataSource: homogeneous,
            dataTextField: "Name",
            dataUrlField: "URL",
            hasChildren:"ParentsID"
        });

    });


        </script>

当前输出&amp;屏幕截图上标有问题。 enter image description here

请帮忙。感谢。

1 个答案:

答案 0 :(得分:1)

请尝试使用以下代码段。

public ActionResult LoadMenu(int? id)
{
    List<TreeModel> list = new List<TreeModel> {
   new TreeModel() { ID=1, Name="Setup", URL="m.facebook.com", HasChild=true},
   new TreeModel() { ID=10, Name="Leave", URL="google.com", ParentsID=1, HasChild=false},
   new TreeModel() { ID=2, Name="EmployeeInfo", URL="m.facebook.com", HasChild=true},
   new TreeModel() { ID=11, Name="Basic Employee", URL="m.facebook.com", HasChild=false, ParentsID=2},

   };

        var nodes = (from n in list
                     where (id.HasValue ? n.ParentsID == id.Value : n.ParentsID == null)
                     select n).ToList();

        return Json(nodes, JsonRequestBehavior.AllowGet);

}