简体   繁体   English

根据Kendo菜单中服务中的数据在新选项卡中打开url

[英]Open url in new tab based on data in service in Kendo Menu

I searched around number of posts, but haven't any solution applicable to my scenario. 我搜索了许多帖子,但没有适用于我的方案的解决方案。 I am population kendo-menu dynamically using an array build via sql. 我正在使用通过sql构建的数组动态填充kendo菜单。

<kendo-menu [items]="items"
            [vertical]="true"
            style="display:inline-block;">
</kendo-menu>

This is the sample I am following: 这是我关注的示例:

https://www.telerik.com/kendo-angular-ui/components/menus/menu/vertical/ https://www.telerik.com/kendo-angular-ui/components/menus/menu/vertical/

Here is how items array is structured: 这是项数组的结构:

export const items: any[] = [
  {
  text: 'Reportingd',
    items: [{ text: 'Dash', url: "https://www.google.com" },  {
    text: 'Realtime',
      items: [{ text: 'DesktopNew', url: "https://www.telerik.com" }, { text: 'laptop', url: "https://www.msn.com" }]
  }]
},
{
  text: 'Other Reporting',
  items: [{ text: 'Training', url: "https://www.msn.com" }, { text: 'UserManual', url: "https://www.msn.com" }, { text: 'Guide',
    items: }]
},
{
  text: 'Tools',
  items:[{ text: 'Training', url: "https://www.msn.com" }]
}];

However, this on click of menu/sub-menu opens url in the same window. 但是,单击菜单/子菜单后会在同一窗口中打开URL。 I want to open in different window or new tab. 我想在其他窗口或新标签页中打开。 HTML <a> tag does not work here. HTML <a>标记在这里不起作用。 Please suggest 请建议

<a href="https://www.thesitewizard.com/" target="_blank">thesitewizard.com</a>

Write select event for kendo menu something like below. 为剑道菜单编写选择事件,如下所示。

<kendo-menu [items]="items" (select)="onSelect($event)"></kendo-menu>

After that in onSelect method use window.open method like below. 之后,在onSelect方法中使用window.open方法,如下所示。

public onSelect({ item }): void {
        if (!item.items) {
            window.open([item.url], "_blank");
        }
    }

was able to resolve. 能够解决。 It is 2 step process though. 虽然是两步过程。 with following array structure given in initial post just open in current window. 在初始窗口中给出的以下数组结构只是在当前窗口中打开。 Therefore, fetched unique MenuID instead of url on initial load. 因此,在初始加载时获取了唯一的MenuID而不是url。 Then as ManirajSS suggested 然后如ManirajSS建议

public onSelect({ item }): void {

//call service to get url for this MenuID

}

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

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