如何获取类型为TreeView.ComboTreeBehaviorName
的组合控件以使其节点默认折叠?
我尝试查看文档here和here,但对我来说似乎完全没有帮助。
我还尝试检查类型(在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 = false
到source
属性以下是一些相关的代码摘录:
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;
});
}
答案 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
}
);