代码之家  ›  专栏  ›  技术社区  ›  nonexistent

Priming(5.2.4)树-无法通过单击展开树节点

  •  0
  • nonexistent  · 技术社区  · 6 年前

    出身背景 :我试图使用PrimeNG的树组件,但在单击展开节点时遇到以下错误:

    UITreeNode.html:6 ERROR TypeError: eventTarget.className.indexOf is not a function
        at Tree.onNodeClick (tree.js:270)
        at UITreeNode.onNodeClick (tree.js:48)
        at Object.eval [as handleEvent] (UITreeNode.html:6)
        at handleEvent (core.js:13589)
        at callWithDebugContext (core.js:15098)
        at Object.debugHandleEvent [as handleEvent] (core.js:14685)
        at dispatchEvent (core.js:10004)
        at eval (core.js:10629)
        at HTMLDivElement.eval (platform-browser.js:2628)
        at ZoneDelegate.invokeTask (zone.js:425)
    

    跟踪错误时,问题代码如下所示:

    Tree.prototype.onNodeClick = function (event, node) {
            var eventTarget = event.target;
            if (eventTarget.className && eventTarget.className.indexOf('ui-tree-toggler') === 0) {
                return;
            }
    

    进一步挖掘 :我在我的树中添加了一个单击事件,以查看事件的外观(尽管这可能完全错误,因为这可能与实际错误不同),并发现当您单击节点时,返回的结果如下:

    SVGAnimatedString {
        baseVal: "svg-inline--fa fa-caret-right fa-w-6 ui-tree-toggler fa-fw", 
        animVal: "svg-inline--fa fa-caret-right fa-w-6 ui-tree-toggler fa-fw"
    }
    

    其他可能相关的依赖项和代码

    "@angular/animations": "^5.2.10",
    "@angular/cdk": "^5.2.1",
    "@angular/common": "^5.2.10",
    "@angular/compiler": "^5.2.10",
    "@angular/core": "^5.2.10",
    "@angular/forms": "^5.2.10",
    "@angular/http": "^5.2.10",
    "@angular/material": "^5.2.1",
    "@angular/platform-browser": "^5.2.10",
    "@angular/platform-browser-dynamic": "^5.2.10",
    "@angular/router": "^5.2.10",
    "primeng": "^5.2.4"
    

    树代码 :

    <p-tree [value]="files" (click)="log($event)"></p-tree>
    

    docs .

    记录方法:

    log(event) {
      console.log(event.target.className);
    }
    

    问题

    或者我的打底/角度的版本已经过时了,这在升级中得到了修复?

    感谢您的帮助!

    0 回复  |  直到 6 年前