Tree 树面板ExtNet没有';不要给孩子们装东西

Tree 树面板ExtNet没有';不要给孩子们装东西,tree,extjs4,Tree,Extjs4,树面板有问题。 问题是孩子们没有表现出来。 我使用extnet剃须刀引擎 此代码位于cshtml文件中: TreePanel treePanelParent = X.TreePanel() .ID("treePanelParent") .Height(200) .RootVisible(false) .Root(rt => rt .Add(Html.X() .Node() .NodeID("0") .Text("Click Parent Lo

树面板有问题。 问题是孩子们没有表现出来。 我使用extnet剃须刀引擎

此代码位于cshtml文件中:

TreePanel treePanelParent = X.TreePanel()
   .ID("treePanelParent")
   .Height(200)
   .RootVisible(false)
   .Root(rt => rt
   .Add(Html.X()
   .Node()
   .NodeID("0")
   .Text("Click Parent Location")))
   .Store(st => st
   .Add(X.TreeStore()
   .Proxy(px => px
   .Add(Html.X()
   .AjaxProxy().Json(true)
   .Url(Url.Action("GetParentDatas", "Location"))
   .Reader(reader => reader.Add(Html.X().JsonReader()
   .Root("data")
   .IDProperty("Id")))))
));
treePanelParent.GetRootNode().Expand(true);
我有一个父母有两个孩子

该控制器:

        public ActionResult GetParentDatas() {
            NodeCollection nodes = new NodeCollection();

            Node Node = new Node();
            Node.Text = "satu";
            Node.Icon = Icon.Map;
            Node.Leaf = false;
            Node.NodeID = "1";

            Node Node3 = new Node();
            Node3.Text = "tiga";
            Node3.Icon = Icon.Map;
            Node3.Leaf = false;
            Node3.NodeID = "3";

            Node Node2 = new Node();
            Node2.Text = "dua";
            Node2.Icon = Icon.Map;
            Node2.Leaf = true;
            Node2.NodeID = "2";

            Node.Children.Add(Node2);
            Node.Children.Add(Node3);
            return Json(new { data = nodes.ToJson() }, JsonRequestBehavior.AllowGet);
    }
{"data":"[
   {id:\"1\",iconCls:X.net.RM.getIcon(\"Map\"),text:\"satu\",children:[
      {id:\"2\",leaf:true,iconCls:X.net.RM.getIcon(\"Map\"),text:\"dua\"},
      {id:\"3\",iconCls:X.net.RM.getIcon(\"Map\"),text:\"tiga\"}
   ]}
]"}
如果我指示控制器,则此格式为json代码:

        public ActionResult GetParentDatas() {
            NodeCollection nodes = new NodeCollection();

            Node Node = new Node();
            Node.Text = "satu";
            Node.Icon = Icon.Map;
            Node.Leaf = false;
            Node.NodeID = "1";

            Node Node3 = new Node();
            Node3.Text = "tiga";
            Node3.Icon = Icon.Map;
            Node3.Leaf = false;
            Node3.NodeID = "3";

            Node Node2 = new Node();
            Node2.Text = "dua";
            Node2.Icon = Icon.Map;
            Node2.Leaf = true;
            Node2.NodeID = "2";

            Node.Children.Add(Node2);
            Node.Children.Add(Node3);
            return Json(new { data = nodes.ToJson() }, JsonRequestBehavior.AllowGet);
    }
{"data":"[
   {id:\"1\",iconCls:X.net.RM.getIcon(\"Map\"),text:\"satu\",children:[
      {id:\"2\",leaf:true,iconCls:X.net.RM.getIcon(\"Map\"),text:\"dua\"},
      {id:\"3\",iconCls:X.net.RM.getIcon(\"Map\"),text:\"tiga\"}
   ]}
]"}

我终于有了答案

我只是在控制器中更改代码返回

之前:

return Json(new { data = nodes.ToJson() }, JsonRequestBehavior.AllowGet);
成为:

return Content(nodes.ToJson());
并在cshtml中删除

.Root("data")

您需要将代码的格式设置为可读的,否则不要期望得到任何答案。我只做了基本的工作,您可能需要进一步改进第一个代码部分。