fly*_*ire 5 html javascript extjs
在Ext Js中,我希望我的一些按钮像链接一样工作(即<a href...).
我怎样才能做到这一点.
现在我正在添加一个处理程序window.location.href=http://.....
但我认为应该有一种更简单的方法 - 比如在菜单项中添加href属性.
一些想法?
这就是它的完成方式...为了更加可移植,你可以扩展Ext.Button到Ext.ux.LinkButton(或者其他)并在这个扩展类中实现属性和所需的行为(只是一个快速而又脏的例子):
Ext.ux.LinkButton = Ext.extend(Ext.Button, {
href: null,
handler: function() {
if (this.href) {
window.location.href = this.href;
}
}
});
Ext.reg( "ux-linkbutton", Ext.ux.LinkButton );
var btn = new Ext.ux.LinkButton({
text: "Link to Google",
href: "http://www.google.com"
});
Run Code Online (Sandbox Code Playgroud)
编辑:
简单的外观变化:
Ext.ux.LinkButton = Ext.extend(Ext.Button, {
href: null,
template: new Ext.Template(
['<table id="{4}" cellspacing="0" class="x-btn {3}"><tbody class="{1}">',
'<tr><td class="x-btn-tl"><i> </i></td><td class="x-btn-tc"></td><td class="x-btn-tr"><i> </i></td></tr>',
'<tr><td class="x-btn-ml"><i> </i></td><td class="x-btn-mc"><em class="{2}" unselectable="on"><a href="{0}"></a></em></td><td class="x-btn-mr"><i> </i></td></tr>',
'<tr><td class="x-btn-bl"><i> </i></td><td class="x-btn-bc"></td><td class="x-btn-br"><i> </i></td></tr>',
'</tbody></table>'], {compiled: true}),
buttonSelector : 'a:first-child',
getTemplateArgs : function(){
return [this.href, 'x-btn-' + this.scale + ' x-btn-icon-' + this.scale + '-' + this.iconAlign, this.getMenuClass(), this.cls, this.id];
},
handler: function(b, e) {
if (this.href) {
e.stopEvent();
window.location.href = this.href;
}
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17793 次 |
| 最近记录: |