请问Ext如何给已经创建好的Toolbar添加按钮

dunerunner 2010-10-13 10:07:16

Ext.onReady(function () {
var tbar = new Ext.Toolbar({
height: 50,
items: [
new Ext.Button({
text: "button here",
handler: function (btn) {
Ext.MessageBox.alert("it's a button here!");
}
})
]
});

tbar.addButton([{text: "save"},{text: "close"}]); // 在这里可以添加上按钮

var p = new Ext.Panel({
tbar: tbar,
renderTo: Ext.getBody()
});

// 如果在这里使用addButton就不行
});



请问如果我想在toolbar创建好之后通过tbar.addButton([{text: "save"},{text: "close"}]);动态添加按钮应该怎么实现?
希望各位路过的朋友帮忙,谢谢!
...全文
112 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hoojo 2010-10-13
  • 打赏
  • 举报
回复
Ext.onReady(function () {
var tbar = new Ext.Toolbar({
height: 50,
items: [
new Ext.Button({
text: "button here",
handler: function (btn) {
Ext.MessageBox.alert("it's a button here!");
}
})
]
});

tbar.addButton([{text: "save"},{text: "close"}]); // 在这里可以添加上按钮

var p = new Ext.Panel({
tbar: tbar,
renderTo: Ext.getBody()
});

// 如果在这里使用addButton就不行
tbar.addButton([{text: "save2"},{text: "close2"}]);
tbar.doLayout();//重新渲染布局
});

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧