【发布时间】:2017-07-05 10:38:06
【问题描述】:
使用 PrimeNG,我可以滚动到 TreeNode:
在html中:
<p-tree #mytreeid id="mytree"></p-tree>
在 Angular 中:
@ViewChild("mytree") mytree: Tree;
// selection is the TreeNode you want to scroll into view
scrollToSelectionPrimeNgDataTree(selection, tree, elementIdName) {
if (tree.value !== null) {
let index = tree.value.indexOf(selection);
let ele = document.getElementById(elementIdName).querySelectorAll("p-treenode")[index];
ele.scrollIntoView();
//ele.focus();
}
}
问题:如何使 TreeNode(即“选择”)集中?我尝试调用focus()方法,但是focus()不是Element的方法。
【问题讨论】:
-
其实我想要的是TreeNode可以有一个属性,比如[selected],当它设置为'true'时,Tree会滚动到节点并专注于它,即。节点被“选中”。