简体   繁体   English

单击事件以显示树元素的名称

[英]Click Event To Show Name of Tree Elements

I am trying to use jqxTree for an Angular project and so far, used the following to render the items in it:我正在尝试将jqxTree用于Angular项目,到目前为止,使用以下内容呈现其中的项目:

HTML : HTML

<jqxExpander [theme]="'material'" [width]="300" [height]="400"
             [showArrow]="false" [toggleMode]="'none'">
  <div>
    Folders
  </div>
  <div style="overflow: hidden;">
    <jqxTree [theme]="'material'" #treeReference
             [width]="'100%'" [height]="'100%'" [source]="treeSource">
    </jqxTree>
  </div>
</jqxExpander>

TypeScript : TypeScript

 @ViewChild('treeReference') tree: jqxTreeComponent;
  ngAfterViewInit(): void {
      setTimeout(() => {
          this.tree.selectItem(null);
      });
  }

  treeSource: any[] =
  [
      {
          icon: "https://www.jqwidgets.com/angular/images/mailIcon.png", label: "Mail", expanded: true,
          items:
          [
              { icon: "https://www.jqwidgets.com/angular/images/calendarIcon.png", label: "Calendar" },
              { icon: "https://www.jqwidgets.com/angular/images/contactsIcon.png", label: "Contacts", selected: true }
          ]
      },
      {
          icon: "https://www.jqwidgets.com/angular/images/folder.png", label: "Inbox", expanded: true,
          items:
          [
              { icon: "https://www.jqwidgets.com/angular/images/folder.png", label: "Admin" },
              { icon: "https://www.jqwidgets.com/angular/images/folder.png", label: "Corporate" },
              { icon: "https://www.jqwidgets.com/angular/images/folder.png", label: "Finance" },
              { icon: "https://www.jqwidgets.com/angular/images/folder.png", label: "Other" },
          ]
      },
      { icon: "https://www.jqwidgets.com/angular/images/recycle.png", label: "Deleted Items" },
      { icon: "https://www.jqwidgets.com/angular/images/notesIcon.png", label: "Notes" },
      { iconsize: 14, icon: "https://www.jqwidgets.com/angular/images/settings.png", label: "Settings" },
      { icon: "https://www.jqwidgets.com/angular/images/favorites.png", label: "Favorites" }
  ];

What I am trying is to get the item or node name from the tree.我正在尝试从树中获取项目或节点名称。 Suppose, under Mail, it has two nodes Calendar and Contacts.假设在Mail 下,它有两个节点Calendar 和Contacts。 If user clicks on Calendar, it should show the name Calendar in a alert box.如果用户单击日历,它应该在警报框中显示名称日历 I am not sure if the tree has click events for the items, tried to use a button to retrieve name from it as follows:我不确定树是否有项目的点击事件,尝试使用按钮从中检索名称,如下所示:

btnShowItem() {
   alert(this.tree.selectItem.name);
}

But the above only shows selectedItem in the alert box.但上面只在警报框中显示 selectedItem 。 Is there any appropriate way to retrieve the names of the items on click?是否有任何适当的方法可以在单击时检索项目的名称?

NB : Here's a link for testing - jqxTree注意:这是一个测试链接 - jqxTree

Try and look inside the JQXTreeComponent and look for a nodeName property.尝试查看 JQXTreeComponent 内部并查找 nodeName 属性。 After that, you would need to make a method that would return the matching nodeName with the one that you clicked on.之后,您需要创建一种方法,该方法将返回与您单击的节点名称匹配的节点名称。 I'm not particularly familiar with JQX components, thus I can't say how you would loop through the nodes.我对 JQX 组件不是特别熟悉,因此我不能说你将如何循环遍历节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM