extjs4 给button动态添加菜单,怎么添加啊

ianafollow 2015-09-29 10:57:49
如题,有一个按钮,是用Ext.Button创建,然后单击后弹出菜单,菜单内容和地址是从后台传过来了,所以不知道怎么添加到button中,看了网上的,也找不到方法,哪位大姐大哥会啊?
...全文
291 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ianafollow 2015-10-09
  • 打赏
  • 举报
回复
引用 12 楼 u010087908 的回复:
[quote=引用 10 楼 ianafollow 的回复:] [quote=引用 9 楼 u010087908 的回复:] 试一下 menu.on('click', function(menu, item, e, eOpts) { ... });
试过,没有用[/quote] console显示什么错误?[/quote] 没错误,就点了没反应
ianafollow 2015-10-08
  • 打赏
  • 举报
回复
var basic_button = Ext.create('Ext.Button',{ renderTo:'toolbar', text:'系统管理', width : 90, height : 20, //enableToggle : false, style : { marginBottom : '10px', // 距底部高度 marginLeft : '20px', // 距左边宽度 marginRight : '10px', // 距右边宽度 marginTop : '10px' // 踞顶部高度 } }); basic_button.on('click',function(){ Ext.Ajax.request({ url:'getBasicMenu.action', callback:function(options, success, response){ var json = Ext.JSON.decode(response.responseText); if(true == json.success){ var menu =Ext.create('Ext.menu.Menu',{}); menu.removeAll(); for(var i=0;i<json.data.length;i++){ menu.add({ id: json.data[i].id, text:json.data[i].text, url:json.data[i].url , handler:function(){alert(11111);} }); } basic_button.menu = menu; }else{ alert("登录超时,请重新登录!"); window.location.href='login.jsp'; } }, method:'POST' }); });
ianafollow 2015-10-08
  • 打赏
  • 举报
回复
引用 2 楼 u010087908 的回复:
var menu = Ext.create('Ext.menu.Menu', {
    width: ...//自己定义,
    items: [{
        text: '后台数据 1'
    },{
        text: '后台数据 2'
    },{
        text: '后台数据 3'
    }]
});

button.menu = menu;
在吗,菜单中的选项也是从后台选出来的,现在问题是点击菜单中的选项,绑定的点击事件无反应
NANU-NANA 2015-10-08
  • 打赏
  • 举报
回复
引用 10 楼 ianafollow 的回复:
[quote=引用 9 楼 u010087908 的回复:] 试一下 menu.on('click', function(menu, item, e, eOpts) { ... });
试过,没有用[/quote] console显示什么错误?
ianafollow 2015-10-08
  • 打赏
  • 举报
回复
写在哪边呢才有用呢!
ianafollow 2015-10-08
  • 打赏
  • 举报
回复
引用 9 楼 u010087908 的回复:
试一下 menu.on('click', function(menu, item, e, eOpts) { ... });
试过,没有用
NANU-NANA 2015-10-08
  • 打赏
  • 举报
回复
试一下 menu.on('click', function(menu, item, e, eOpts) { ... });
ianafollow 2015-10-08
  • 打赏
  • 举报
回复
引用 5 楼 u010087908 的回复:
你的代码里没有给menuitem定义任何事件,所以点击后没啥反应也是正常的。
应该怎么写啊
ianafollow 2015-10-08
  • 打赏
  • 举报
回复
引用 5 楼 u010087908 的回复:
你的代码里没有给menuitem定义任何事件,所以点击后没啥反应也是正常的。
大神,快点回复,我好着急
ianafollow 2015-10-08
  • 打赏
  • 举报
回复
menu.add({ id: json.data[i].id, text:json.data[i].text, url:json.data[i].url , handler:function(){alert(11111);} }); 中的handler难道不是点击事件吗,应该怎么呢
NANU-NANA 2015-10-08
  • 打赏
  • 举报
回复
你的代码里没有给menuitem定义任何事件,所以点击后没啥反应也是正常的。
NANU-NANA 2015-10-01
  • 打赏
  • 举报
回复
var menu = Ext.create('Ext.menu.Menu', {
    width: ...//自己定义,
    items: [{
        text: '后台数据 1'
    },{
        text: '后台数据 2'
    },{
        text: '后台数据 3'
    }]
});

button.menu = menu;
ianafollow 2015-09-29
  • 打赏
  • 举报
回复
我发现最近几个月,在此站上发的贴都没人回答,不知为啥

87,902

社区成员

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

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