extjs中的listeners怎么不起作用

嘿卟 2011-06-23 02:31:20
我自定义了一个组件叫RoleList,代码如下

var roleStore = new Ext.data.JsonStore({
url : URL_ROLESTORE,
root : "result",
fields : ['id', 'authority', 'description']
});
roleStore.load();


component.list.RoleList = Ext.extend(Ext.grid.GridPanel, {
store : roleStore,
sm : new Ext.grid.RowSelectionModel({
singleSelect : true
}),
initComponent : function() {
this.addEvents({
selectrole : true
})
this.columns = [
{
xtype : 'gridcolumn',
dataIndex : 'authority',
header : LABEL_ROLE_AUTHORITY,
sortable : true
}, {
xtype : 'gridcolumn',
dataIndex : 'description',
header : LABEL_ROLE_DESCRIPTION,
sortable : true
} ];
this.sm.on("rowselect",this.onSelectRole);
component.list.RoleList.superclass.initComponent.call(this);

},

onSelectRole : function(sm, rowIdx, r){
this.fireEvent('selectrole', this, sm, rowIdx, r);
}
});
Ext.reg('rolelist', component.list.RoleList);


然后我在另一个组件里面添加了listeners,希望可以触发自定义的selectrole 事件,可是没有效果,代码如下:

application.user.UserPrivilege = Ext.extend(Ext.Panel, {
title : TITLE_USERPRIVILEGE,
layout : 'border',
initComponent : function(){
this.items=[{
layout: "vbox",
split : true,
region: "center",
items : [
this.buildUserList(),
this.buildUserInfoForm()
]
},this.buildRoleList()
];
application.user.UserPrivilege.superclass.initComponent.call(this);
},
buildRoleList : function(){
return {
xtype : "rolelist",
region : "west",
width : 300,
id : "rolelist",
listeners : {
scope : this,
'selectrole' : function(){alert("ok")}
}
}
},

buildUserList : function(){
return {
xtype : "userlist",
flex : 1,
id : "userlist",
split : true,
listeners : {

}
}
},

buildUserInfoForm : function(){
return {
xtype : "userinfoform",
flex : 1,
width : "100%",
id : "userinfo",
split : true,

onSaveUser : function(){
this.el.mask('Please wait', 'x-mask-loading');
this.getForm().submit({
method : "POST",
success : function(form,action){
this.el.unmask();
this.findById("userNameField").disable();
Ext.MessageBox.alert("Prompt", "save success");
this.findById("passwordField").hide();
this.findById("rePasswordField").hide();
Ext.getCmp("userlist").getStore().reload();
},
failure : function(form,action){
this.el.unmask();
Ext.MessageBox.alert("Prompt", "save faild");
}
})
},

onNewUser : function(){
this.getForm().reset();
this.findById("passwordField").show();
this.findById("rePasswordField").show();
this.getForm().url=URL_NEWUSER;
this.findById("userNameField").enable();
roleNotAssignedStore.load();
}
}
},
onRoleListClick : function(rolelist,sm,rowIdx,d){
alert(d);
userStore.proxy.setUrl(URL_USERLISTBYROLE);
/*
this.getSelectionModel().on('rowselect',function(sm, rowIdx, r){
var store=userList.getStore();
store.proxy.setUrl(URL_USERLISTBYROLE);
store.load({params:{roleId:r.data.id}});
});*/
}
});

...全文
1562 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
失去乐山贼 2011-06-24
  • 打赏
  • 举报
回复
下载个中文API看看呗。
goldzql 2011-06-24
  • 打赏
  • 举报
回复
initComponent:function(){
.........
this.addEvents('gridRowClk');
this.on('rowclick',this.clkByGrid,this);
},
clkByGrid:function(g,i,e){
this.fireEvent('gridRowClk',g,i,e);
}
使用:
this.on('gridRowClk',this.loadByGrid,this);
loadByGrid:function(g,i,e){}

嘿卟 2011-06-23
  • 打赏
  • 举报
回复
楼上的哥哥 怎么做,能具体吗?
一品 2011-06-23
  • 打赏
  • 举报
回复
需要你先把自定义事件添加到事件里面去,没有添加的话,只能做为方法去调用,监听不到的
嘿卟 2011-06-23
  • 打赏
  • 举报
回复
click事件是可以的的,但是我要触发selectrole 事件,这是个自定义事件
this.addEvents({
selectrole : true
})
flyerwing 2011-06-23
  • 打赏
  • 举报
回复
{
........
listeners:{"click":function(){alert('aaa');}},
........
}

87,915

社区成员

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

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