工具栏中的ExtJS按钮
我想问一下,当if语句为true时,是否有可能只在工具栏中显示一个按钮 对于我的情况,我这里有一个片段工具栏中的ExtJS按钮,extjs,Extjs,我想问一下,当if语句为true时,是否有可能只在工具栏中显示一个按钮 对于我的情况,我这里有一个片段 { xtype: 'toolbar', dock: 'bottom', items: [ { xtype: 'button', text: 'Pay!',
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
xtype: 'button',
text: 'Pay!',
handler: function() {
console.log('haha');
}
}
]
}
有按钮的工具栏
但我只想在网格不为空时显示“支付”按钮(我还有一个网格)
这怎么可能
谢谢 必须绑定到所有指示行计数更改的事件。其中大多数是商店活动:
xtype:'grid',
tbar:[{
xtype:'button',
itemId:'Test'
}],
buttonchange:function() {
this.down('button[itemId=Test]').setVisible(this.getStore().getCount()>0);
},
listeners:{
viewready:function(gridview) {
var grid = gridview.ownerCt;
grid.buttonchange();
store.on({
load: grid.buttonchange(),
add: grid.buttonchange(),
remove: grid.buttonchange(),
clear: grid.buttonchange(),
filterchange: grid.buttonchange(),
scope: grid
});
}
}
由于网格数据由存储处理,因此必须添加存储加载事件侦听器
我为您创建。如果您使用的是ExtJs5/6+,则可以将按钮的可见性绑定到商店计数 比如:
{
xtype: 'toolbar',
dock: 'bottom',
items: [
{
xtype: 'button',
text: 'Pay!',
bind: {
hidden: '{!storeCount}'
}
handler: function() {
console.log('haha');
}
}
]
}
您需要自己设置storeCount,因为无法直接访问该属性(请参阅)
假设您在视图模型中声明了您的商店,那么在视图控制器中您应该能够执行以下操作
initViewModel: function(viewModel) {
viewModel.bind('{yourStore}', function(store) {
if(store) {
store.on('datachanged', function () {
this.set('storeCount', this.getCount()) // this is the viewModel as I set the scope of the function
});
}
}, viewModel);
}