如何在AngularJS中检测树控件中的“空格”键

时间:2017-12-07 12:20:08

标签: angularjs angular-ui keyevent treecontrol

我在1.5版本中对AngularJS的angular-ui中的treecontrol有问题。 Treecontrol具有名为 on-selection 的指令,它检测“输入”或鼠标单击并从treecontrol发送选项到输入。我想要“Space”键的相同行为,但我不知道如何将它添加到treecontrol。此外,正常的ng-keypress不起作用。我无法修改任何angular-ui文件。有谁知道这个问题的解决方案?

编辑:代码:

template: '<div class="autocomplete"><treecontrol class="tree-light" tree-model="source" options="ctrl.treeOptions" filter-expression="filter" expanded-nodes="expandedNodes" on-selection="nodeSelect(node)" ng-keypress="spaceClicked($event)">' +
          '<span><i class="enms enms-{{node.type}}"></i>{{node.name | translate}}</span></treecontrol></div>',
link: function(scope, elem, attrs, ctrl) {
    this.ctrl = ctrl;

    scope.nodeSelect = function (node) {
    // Element selektieren
    scope.onSelect()(node);
};

scope.spaceClicked = function (event) {
     console.log("Clicked: ");
     console.log(event.keyCode);
};

实例: 屏幕1: enter image description here

屏幕2: enter image description here

当用户开始在输入中键入任何内容时,将出现treecontrol并显示匹配的选项(屏幕1)。现在用户需要单击鼠标选项或单击“Enter”按钮添加选项输入(屏幕2)。我想为“Space”键获得相同的行为。我希望现在我的问题很清楚了:))

0 个答案:

没有答案