【问题标题】:Searching inside Kendo Hierarchical Datasource在 Kendo 分层数据源中搜索
【发布时间】:2014-06-20 10:32:44
【问题描述】:

我正在尝试在 Kendo 分层数据源中搜索项目。需要获取该项目的 uid 并以编程方式选择 Kendo Treeview 上的该项目节点。

这里是代码。请原谅我草率的算法。

function findTreeviewNodeById(haystack, needle) {
    var uid = null;

    for (var i = 0; i < haystack.length; i++) {
        if (haystack[i].id == needle) {
            uid = haystack[i];
        }
        else if (haystack[i].hasChildren) {
            uid = findTreeviewNodeById(haystack[i].children.data(), needle);
        }

        if (uid != null)
            break;
    }

    return uid;
}

以上代码仅适用于具有 2 级深度的分层数据源。如果我尝试在它达到第 3 级时为其提供更深层次的数据源,则此行 haystack[i].children.data() 返回空子项(它应该不为空)。为什么第三级数据源是空的?即使 Treeview 完美地显示了 Hierarchical 数据源中包含的所有数据。我在这里遗漏了什么吗?

【问题讨论】:

    标签: jquery kendo-ui hierarchical-data kendo-treeview kendo-datasource


    【解决方案1】:

    我必须在递归之前调用 load() 到 haystack,以便加载 haystack 的子项。

    function findTreeviewNodeById(haystack, needle) {
        var uid = null;
    
        for (var i = 0; i < haystack.length; i++) {
            haystack[i].load();
            if (haystack[i].id == needle) {
                uid = haystack[i];
            }
            else if (haystack[i].hasChildren) {
                uid = findTreeviewNodeById(haystack[i].children.data(), needle);
            }
    
            if (uid != null)
                break;
        }
    
        return uid;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-26
      • 1970-01-01
      • 2022-01-24
      • 2013-10-16
      相关资源
      最近更新 更多