如何让vss sdk treeview默认折叠?

时间:2018-07-16 21:18:43

标签: typescript azure-devops vssdk

如何获取类型为TreeView.ComboTreeBehaviorName的组合控件以使其节点默认折叠?

我尝试查看文档herehere,但对我来说似乎完全没有帮助。

我还尝试检查类型(在vss.d.ts中)以查看是否可以设置属性:

  • 我发现maxAutoExpandDropWidth声称它Specifies the max size when auto-expand drop bigger than combo,但是将其设置为0或1似乎没有任何效果。
  • 我找到了dropOptions?: IComboDropOptions;,但似乎没有 也具有展开/折叠的任何属性。
  • 我尝试将属性collapsed: true添加到IComboOptions
  • Controls.Enhancement.enhance方法的签名似乎 建议我可以将某些选项作为type属性的一部分进行传递 在IComboOptions上,但是我尝试了但不能这样做,因为 type属性需要一个字符串,而不是一个对象。
  • 在通过树之前为所有节点设置node.expanded = falsesource属性

以下是一些相关的代码摘录:

import * as Controls_Combos from "VSS/Controls/Combos";
import * as Controls from "VSS/Controls";
import * as TreeView from "VSS/Controls/TreeView";



 this._$areaInput = $("<input type='text' id='inputAreaPicker' />")
                .val(someValueThatDoesnotMatter)
                .bind("blur", (e) => {
                    this._updateSomeOtherField();
                    this._validate();
                });
}

...

        <Controls_Combos.Combo>Controls.Enhancement.enhance(
            Controls_Combos.Combo,
            this._$areaInput,
            <Controls_Combos.IComboOptions> {
                type: TreeView.ComboTreeBehaviorName,
                source: ConvertToTreeNodes(someItems),  // loads multi-level tree successfully
                mode: 'drop',
                allowEdit: false,
                maxAutoExpandDropWidth: 1, // seems to have no effect
                collapsed: true  // no effect
            }
        );


export function ConvertToTreeNodes(items): TreeView.TreeNode[] {
    // let _this = this;
    return $.map(items, function (item) {
        let node = new TreeView.TreeNode(item.name);
        node.id = item.id;
        if (item.children && item.children.length > 0) {
            node.addRange(ConvertToTreeNodes(item.children));
        }
        node.expanded = false;
        return node;
    });
}

1 个答案:

答案 0 :(得分:0)

答案是一个名为'treeLevel'的未记录属性:

<Controls_Combos.Combo>Controls.Enhancement.enhance(
            Controls_Combos.Combo,
            this._$areaInput,
            <Controls_Combos.IComboOptions> {
                type: TreeView.ComboTreeBehaviorName,
                source: ConvertToTreeNodes(someItems),
                mode: 'drop',
                allowEdit: false,
                treeLevel: 0 // collapse to first level by default

            }
        );

I've requested that it be documented