javascript 在 ExtJS 中生成普通链接 (<a href="...">)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3263790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate a normal Link (<a href="...">) in ExtJS
提问by Jeremy S.
I'm struggling with a really simple problem here.
我在这里遇到了一个非常简单的问题。
I want to generate a normal link in frontend but it seems to don't work somehow. Here is the code I use for the generation of the link (the link was a button before which opened a new window with a specified URL on click).
我想在前端生成一个普通链接,但它似乎以某种方式不起作用。这是我用于生成链接的代码(链接是一个按钮,之前单击该按钮会打开一个带有指定 URL 的新窗口)。
{
xtype: 'button',
id: 'PrintTool',
tooltip: 'Printer Friendly',
iconCls: 'icon-printerFriendly',
html: '<a href=\"http:\/\/www.google.at\">x<\/a>',
listeners: {
'click': function(button,event) {
console.log(this);
console.log(event);
this.restoreClick();
return true;
}
}
}
When ExtJS renders the button it makes, hence I add an html attribute to the object, a link out of it.
当 ExtJS 呈现它制作的按钮时,因此我向对象添加了一个 html 属性,一个链接。
I can see the link with FireBug. When I click the link I get the output
我可以看到与 FireBug 的链接。当我点击链接时,我得到了输出
console.log(this);
console.log(event);
in the console
在控制台中
So the event is fired. But the link gets never opened.
所以事件被触发。但是链接永远不会打开。
I think it has something to do with the CLICK-event getting stopped from ExtJS.
我认为这与从 ExtJS 停止的 CLICK 事件有关。
It seems that despite in Firebug there is no button in the HTML the object passed to the click event is still the button.
似乎尽管在 Firebug 中 HTML 中没有按钮,但传递给 click 事件的对象仍然是按钮。
So me question is, how can a create normal HTML in ExtJS without setting a xtype of button. Or how can I generate a normal link.
所以我的问题是,如何在不设置按钮的 xtype 的情况下在 ExtJS 中创建普通的 HTML。或者我怎样才能生成一个正常的链接。
I used to open a popup after the button was clicked. The popup got blocked from Chrome, IE and various other browser so I have to use a normal link with a URL instead.
我曾经在单击按钮后打开一个弹出窗口。弹出窗口被 Chrome、IE 和各种其他浏览器阻止,所以我必须使用带有 URL 的普通链接。
采纳答案by Jeremy S.
Got an answer to my question in ExtJS forum
在 ExtJS 论坛中得到了我的问题的答案
Use LinkButton an extension written by Animal
使用 LinkButton 一个由 Animal 编写的扩展
回答by tonymayoral
You can also use the html property of a label component and call a controller function from there. Example:
您还可以使用标签组件的 html 属性并从那里调用控制器函数。例子:
{xtype: 'label',
html: 'bla bla? <a href="#" onClick="javascript:appName.app.getController(\'myController\').showRegistration();">Register</a>'
}

