【问题标题】:Kendo treeview HierarchicalDataSource not showing child nodesKendo treeview HierarchicalDataSource 不显示子节点
【发布时间】:2016-03-23 21:18:58
【问题描述】:

我有一个剑道树视图,它显示父节点但看不到子节点。谁能告诉我我哪里出错了。我对这个概念很陌生。我按照下面的链接,但它不工作。 http://demos.telerik.com/kendo-ui/treeview/remote-data-binding

 function treeView() {
        var treeM = new kendo.data.HierarchicalDataSource({
            schema: {
                data: function (response) {
                    console.log("response" + JSON.stringify(response));
                    var rdata = {};
                    if (response.d) {
                        rdata = JSON.parse(response.d);
                    }
                    else {
                        rdata = response;
                    }
                    return rdata; // ASMX services return JSON in the following format { "d": <result> }.
                },
                model: {
                    hasChildren: true,
                    id: "ID",
                    expanded: true,
                    fields: {
                        ID: { editable: false, nullable: false, type: "string" },
                        LINK: { editable: true, nullable: true, type: "string" },
                                          },
                },
            },
            transport: {
                read: {
                    url: "/getParent",
                    contentType: "application/json; charset=utf-8",
                    type: "POST",
                    datatype: "json"
                },
                parameterMap: function (data, type) {
                    if ((type == "update") || (type == "create") || (type == "destroy")) {
                        console.log('parameterMap:');
                        return JSON.stringify({ "LinksJson": data });
                        console.log(JSON.stringify(data));
                    } else {
                        return data;
                    }
                }
            }
        });

                 $("#treeview1").kendoTreeView({
            dataSource: treeM,
            dataValueField: "ID",
            dataTextField: ["LINK","Name"]
        });

    }

    $("#treeview").on("click", ".k-in", function (e) {
        var tree = $("#treeview").data('kendoTreeView');
        tree.toggle($(e.target).closest(".k-item"));
    });


    $(document).ready(function () {
        treeView();
    });

服务:

 [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string getParent()
    {
        using (var context = new Data.Entities())
        {
            IQueryable<ERPv2.Data.Links> dataQuery = from x in context.Links
                                                          where x.ParentID == 68
                                                         select x;
            var newQry = dataQuery.AsEnumerable().Select(c => new
                         {
                             ID = c.ID,
                              Name = c.Name,
                             Children = HasChildren(231)
                         });
            JavaScriptSerializer JSON = new JavaScriptSerializer();
            return JSON.Serialize(newQry);

        }
    }




      [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public bool HasChildren(int ID)
        {
            using (var context = new Data.Entities())
            {
                IQueryable<ERPv2.Data.Links> dataQuery = from x in contextLinks
                                                             where x.ParentID == ID
                                                             select x;

                return dataQuery.AsEnumerable().Any();
            }
        }

【问题讨论】:

    标签: kendo-ui treeview


    【解决方案1】:

    即使您尝试查看子节点,它也会尝试调用 getLinks 而不是 getreports。 从我所见,您应该只有一种获取父母和孩子的方法。可以是每个父节点内的数组。 你能把来自getReports方法的数据结合到getlinks本身中并试一试吗?

    【讨论】:

    • 感谢您的建议,我从 1 天开始就一直在尝试您所说的内容,但不知何故我无法编写查询。我已添加 LINQ 查询,请检查并建议我并更新代码
    【解决方案2】:

    您应该尝试在此处使用硬编码值使其正常工作,然后使用服务进行配置。 http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#configuration-dataSource

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-28
      相关资源
      最近更新 更多