[code="java"] this.gridPanel = new Ext.grid.GridPanel( {
id : 'gridpanel',
store : this.store,
cm : this.cm,
sm : this.sm,
// trackMouseOver: false,
loadMask : true,
// 超过长度带自动滚动条
autoScroll : true,
border : false,
// collapsible: true,
// animCollapse: false,
stripeRows : true,
viewConfig : viewConfig,
listeners : {
'celldblclick' : {// 双击时执行修改
fn : this.onEdit,
scope : this
},
'contextmenu' : function(e) {
e.stopEvent();
}
},
tbar : this.roleBar,
bbar : this.pToolbar
});
Ext.Ajax.request( {
url : "DATA/control/Permissions.ashx",
// disableCaching:false,
timout : 300,
success : function(response, option) {
if (response.responseText == "") {
return;
}
/*返回的json : [{"id":"ROLE_ADD","text":"添加","iconCls":"page_add","tooltip":"添加新纪录","handler":"this.createAdd"," scope":"this"} ]
*/
this.roleBar = new Ext.Toolbar(eval('('
+ response.responseText + ')'));
this.roleBar.render('gridpanel');
},
failure : function() {
Ext.Msg.alert("提 示", "权限初始化失败!");
},
params : {
id : "addColumns"
}
// timeout:5000,
});
[/code]
// 生成toolbar 以后 为什么 点击按钮事件的时候错误( 对象不支持此属性或方法 ) , 还有 this.roleBar.render(this.gridPanel.tbar); 的时候 this.gridPanel.tbar 不是对象呢 ?
[b]问题补充:[/b]
[code="java"] var grid = new Ext.grid.GridPanel({ });
tbar.render(grid.tbar); [/code]
[color=red] [b]上面的可以为什么下面的这种就不行呢 ?[/b][/color]
[code="java"] this.grid = new Ext.grid.GridPanel({ });
tbar.render(this.grid.tbar); //错误 this.grid 未定义..[/code]
不知道这个是不是你想要的,动态添加工具栏,我帮你做了一个示例
[code="js"]
Ext.onReady(function() {
var myData = [
['3m Co',71.72,0.02,0.03,'9/1 12:00am'],
['Alcoa Inc',29.01,0.42,1.47,'9/1 12:00am'],
['Altria Group Inc',83.81,0.28,0.34,'9/1 12:00am'],
['United Technologies Corporation',63.26,0.55,0.88,'9/1 12:00am'],
['Verizon Communications',35.57,0.39,1.11,'9/1 12:00am'],
['Wal-Mart Stores, Inc.',45.45,0.73,1.63,'9/1 12:00am']
];
var store = new Ext.data.SimpleStore({
fields: [
{name: 'company'},
{name: 'price', type: 'float'},
{name: 'change', type: 'float'},
{name: 'pctChange', type: 'float'},
{name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia'}
]
});
store.loadData(myData);
var grid = new Ext.grid.GridPanel({
store: store,
columns: [
{id:'company',header: "Company", width: 160, sortable: true, dataIndex: 'company'},
{header: "Price", width: 75, sortable: true, renderer: 'usMoney', dataIndex: 'price'},
{header: "Change", width: 75, sortable: true, dataIndex: 'change'},
{header: "% Change", width: 75, sortable: true, dataIndex: 'pctChange'},
{header: "Last Updated", width: 85, sortable: true, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'lastChange'}
],
stripeRows: true,
autoExpandColumn: 'company',
height:280,
width:500,
tbar : new Ext.Toolbar([{text : '我是第一个tbar上的按钮'}]),
buttons : [{
text : '生成tbar',
handler : function(){
var tbar = new Ext.Toolbar([{"id":"ROLE_ADD","text":"添加","iconCls":"page_add","tooltip":"添加新纪录","handler":"this.createAdd"," scope":"this"}]);
tbar.render(grid.tbar);
}
}],
title:'Array Grid'
});
grid.render(document.body);
});
[/code]
这个是变量作用域的问题了.你可以去看看相关的资料了解一下Extjs变量和函数的作用域(scope)