【问题标题】:how to expand dxTreeview by page load如何通过页面加载扩展 dxTreeview
【发布时间】:2015-01-12 12:17:44
【问题描述】:

页面加载时,devExtreme dxTreeview控件默认如何展开子节点。请给出一些建议或例子。

【问题讨论】:

    标签: jquery knockout.js devextreme


    【解决方案1】:

    尝试在每个触发器上触发一次点击:

    $( document ).ready( function(){
        $( '.dx-treeview-toggle-item-visibility' ).each( function(){
            $( this ).click();
        } );
    } );
    

    【讨论】:

    • 感谢您的快速回复。它在单级扩展树节点上工作正常。但我需要扩展嵌套树(2 或 3 级)。
    • 你有没有给我提琴,我可以试试看?我认为我的解决方案只需要一点补充,但我不知道是什么
    【解决方案2】:

    您可以尝试递归方法:

    // Declare a function
    var clickRecursive = function ($elements, selector) {
      // Exit recursion
      if ($elements.length === 0) return;
    
      $elements.each(function(){
        // First, click all elements
        $(this).click();
    
        // Then click children
        clickRecursive($(this).find(selector), selector);
      });
    }
    
    $(document).ready(function(){
      var toggleSelector = '.dx-treeview-toggle-item-visibility';
      clickRecursive($(toggleSelector), toggleSelector);
    });
    

    【讨论】:

      【解决方案3】:

      您可以使用expandedExpr 选项。它指定数据源项字段的名称,其值定义相应节点是否展开。例如,您可以像这样初始化 dxTreeView:

      $("#your-selector").dxTreeView({
         dataSource: [
              id: 1, text: 'Item 1', expanded: true, items: [
                  id: 2, text: 'Subitem 1', expanded: true, items: [
                    //...
                  ]
              ]
         ]
      });
      

      您也可以使用expandItem(itemElement) 方法来扩展某些特定节点。

      在此处查看更多信息http://js.devexpress.com/Documentation/ApiReference/UI_Widgets/dxTreeView

      【讨论】:

        猜你喜欢
        • 2020-05-05
        • 2018-03-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-30
        • 1970-01-01
        • 1970-01-01
        • 2023-03-10
        相关资源
        最近更新 更多