【问题标题】:Is it possible to pagination on fancytree?可以在fancytree上进行分页吗?
【发布时间】:2019-06-28 01:25:05
【问题描述】:

现在我必须在同一个页面上渲染很多文档,我正在使用 francytree

问题:性能

我的想法:fancytree 是否提供分页功能?

【问题讨论】:

    标签: javascript jquery pagination fancytree


    【解决方案1】:

    没有。截至 2019 年 6 月,没有内置分页选项可用。

    您必须手动完成,方法是制作大量输入数据并一次将它们分配给树。

    但是,树支持延迟加载。这更像是一棵树的分页。

     $("#tree").fancytree({
        // Initial node data that sets 'lazy' flag on some leaf nodes
        source: [
          {title: "Child 1", key: "1", lazy: true},
          {title: "Folder 2", key: "2", folder: true, lazy: true}
        ],
        lazyLoad: function(event, data) {
          var node = data.node;
          // Issue an Ajax request to load child nodes
          data.result = {
            url: "/getBranchData",
            data: {key: node.key}
          }
        }
      });
    

    【讨论】:

    • 这意味着延迟加载的唯一方法不是其他的正确吗?
    • fancytree 有什么限制?意味着我有超过 5000 个文件夹,并且现在浏览器挂起。
    • Facytree 是用 JS 编写的,JS 没有限制。第一个问题的答案是,树可以垂直和水平生长,而列表只能垂直生长。分页适用于这样的垂直列表。
    • 谢谢,查理。分页适用于此类垂直列表:请提供适当的链接
    【解决方案2】:

    Fancytree 支持父节点下的直接子节点的分页,如下所述。

    但请注意,性能问题通常来自渲染的 DOM 元素的数量,而不是树的数据模型内的节点数量。

    因此它可能是在不同父节点下传播数据的替代方案,并在折叠时丢弃标记。 或者使用ext-grid 来实现视口。

    来自paging tutorial:

    “分页”节点是“分页”类型的状态节点,可以用作缺失数据的占位符。通常,我们会添加一些额外的信息,以便稍后加载缺失的节点。

    [
      {title: "Item 1", key: "node1"},
      {title: "Folder 2", folder: true, expanded: true, key: "node2"},
      {title: "Lazy error", key: "node3", lazy: true},
      {title: "Lazy empty", key: "node4", lazy: true},
      {title: "Lazy paging", key: "node5", lazy: true},
      {title: "More...", statusNodeType: "paging", icon: false, url: "get_children?parent=4321&start=5&count=10"}
    ]
    

    也可以使用 API 创建分页节点,例如在 loadChildren 事件中:

      data.node.addPagingNode({
        title: "More...",
        url: "get_children?parent=4321&start=5&count=10"
      });
    

    分页节点生成特殊事件而不是简单的激活。一个常见的实现会发出一个加载请求并用结果替换“更多...”条目:

    $("#tree").fancytree({
      ...
      clickPaging: function(event, data) {
        data.node.replaceWith({url: data.node.data.url}).done(function(){
          // The paging node was replaced with the next bunch of entries.
        });
      }
    

    【讨论】:

      猜你喜欢
      • 2012-05-17
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多