lisper
22 Aug 2011, 8:50 AM
I'm running the demo code found here:
http://docs.sencha.com/ext-js/4-0/#/guide/application_architecture
I'm trying to extend this code to add and delete users. To do this, I added a "delete" button to the Edit view. This works.
To add a new user I need a window that looks exactly like the old Edit view (without the delete button). So I added this. That works too. But now I have duplicated code in the Add and Edit views which I want to refactor. I want Edit to inherit from Add with the addition of a delete button. So I tried this:
Ext.define('MyApp.view.user.Edit', { extend: 'MyApp.view.user.Add',
alias : 'widget.useredit',
title : 'Edit User',
initComponent: function() {
this.callParent(arguments);
this.buttons.push({ text: 'Delete', action: 'delete' })
}
});
This fails with the following error:
TypeError: Result of expression 'me.buttons' [null] is not an object.
The reason this happens is that the call to this.callParent(arguments) in MyApp.view.user.Add sets the buttons property to null, i.e. if I put this at the end of MyApp.view.user.Add.initComponent:
console.log(this.buttons);
this.callParent(arguments);
console.log(this.buttons);
The output is:
[Object, Object]
null
So... what is the right way to do this?
http://docs.sencha.com/ext-js/4-0/#/guide/application_architecture
I'm trying to extend this code to add and delete users. To do this, I added a "delete" button to the Edit view. This works.
To add a new user I need a window that looks exactly like the old Edit view (without the delete button). So I added this. That works too. But now I have duplicated code in the Add and Edit views which I want to refactor. I want Edit to inherit from Add with the addition of a delete button. So I tried this:
Ext.define('MyApp.view.user.Edit', { extend: 'MyApp.view.user.Add',
alias : 'widget.useredit',
title : 'Edit User',
initComponent: function() {
this.callParent(arguments);
this.buttons.push({ text: 'Delete', action: 'delete' })
}
});
This fails with the following error:
TypeError: Result of expression 'me.buttons' [null] is not an object.
The reason this happens is that the call to this.callParent(arguments) in MyApp.view.user.Add sets the buttons property to null, i.e. if I put this at the end of MyApp.view.user.Add.initComponent:
console.log(this.buttons);
this.callParent(arguments);
console.log(this.buttons);
The output is:
[Object, Object]
null
So... what is the right way to do this?