我需要做的下一步:有幾個按鈕。按任何按鈕都會變成forme狀態,所以一些buttom變得不可見。 我寫了下面的代碼重新繪製extJS中的組件
Loyalty.company.CompanyEditForm = Ext.extend(Loyalty.tools.AdvancedForm,
{
defaultConfig:{
......
currentState: 'READONLY'
// EDIT, CREATE, CREATE_EDIT
},
constructor:function (config) {
Ext.apply(config, this.defaultConfig);
config['owner'] = this;
config['items'] = [];
config['items'] = this.createItems(config);
config['buttons'] = this.createButtons(config);
Loyalty.company.CompanyEditForm.superclass.constructor.call(this, config);
this.loadCompany(config['jsonCompany']);
this.renderingView(config);// here it's ok
},
....
renderingView:function (config){
if (config.currentState == 'READONLY'){
this.items.items[0].disabled = false;
Ext.ComponentQuery.query('#cardNumber')[0].disabled = true;
Ext.ComponentQuery.query('#btnEdit')[0].hidden = false;
Ext.ComponentQuery.query('#btnRewrite')[0].hidden = true;
Ext.ComponentQuery.query('#btnSubmit')[0].hidden = true;
Ext.ComponentQuery.query('#btnCancel')[0].hidden = false;
} else if (config.currentState == 'EDIT'){
this.items.items[0].disabled = false;
Ext.ComponentQuery.query('#cardNumber')[0].disabled = false;
Ext.ComponentQuery.query('#btnEdit')[0].hidden = true;
Ext.ComponentQuery.query('#btnRewrite')[0].hidden = true;
Ext.ComponentQuery.query('#btnSubmit')[0].hidden = false;
Ext.ComponentQuery.query('#btnCancel')[0].hidden = false;
} else if (config.currentState == 'CREATE'){
Ext.ComponentQuery.query('#cardNumber')[0].disabled = false;
Ext.ComponentQuery.query('#btnEdit')[0].hidden = true;
Ext.ComponentQuery.query('#btnRewrite')[0].hidden = false;
Ext.ComponentQuery.query('#btnSubmit')[0].hidden = false;
Ext.ComponentQuery.query('#btnCancel')[0].hidden = false;
}
this.owner.doComponentLayout()
return null;
},
createButtons:function (config, form) {
return [
{
id: 'btnEdit',
text:Loyalty.messages['company.edit.fields.edit'],
handler:function() {
config.currentState = 'EDIT';
config.owner.renderingView(config)
}
} ,
{
xtype:'button',
id: 'btnRewrite',
text:Loyalty.messages['company.edit.fields.rewrite'],
handler:function() {
config.currentState = 'READONLY';
config.owner.renderingView(config)
}
},
{
xtype:'button',
id: 'btnSubmit',
text:Loyalty.messages['company.edit.fields.submit'],
handler:function() {
config.currentState = 'CREATE_EDIT';
config.owner.renderingView(config)
}
},
{
xtype:'button',
id: 'btnCancel',
text:Loyalty.messages['company.edit.fields.cancel'],
handler:function() {
if (config.currentState == 'EDIT' || config.currentState == 'CREATE_EDIT'){
config.currentState = 'READONLY';
config.owner.renderingView(config)
}
}
}
];
},
....
}
);
功能renderingView炒菜很好,當我把它從構造函數。但是當它從按鈕方法調用時,什麼都不會發生。要更改(隱藏)的按鈕狀態。 我認爲重繪問題
感謝您的回答DmitryB – yaroslavTir