The general definition method. Note that the method and function are added differently. (To add a function, you can only use the override method to add a function. If you know it, please do it .)
Define a class and give it a method
Copy codeThe Code is as follows:
Ext. define ('simple. class ',{
Welcome: function (){
Alert ('Welcome to the app ');
}
});
Use Ext. override to overload existing classes and add functions
Copy codeThe Code is as follows:
Ext. override (Simle. Class ,{
GoodBye: function (){
Alert ('Goodbye ');
},
FunAll: function (){
This. welcome ();
This. goodBye ();
}
});
Instantiate a Class Object and call a New Method
Copy codeThe Code is as follows:
Var app = new Simple. Class ();
App. runAll (); // Welcome to the app Goodbye
Another method of heavy load
Copy codeThe Code is as follows:
Simple. Class. override ({
// New members...
});
Example:
Copy codeThe Code is as follows:
Ext. define ('myclick ',{
Extend: 'ext. action ',
InitComponent: function (){
Var me = this;
Var initEnable = true; // initial permission
}
});
Ext. override (MyButton ,{
Mysetenable: function (B) {// added the custom function setting button permission
If (this. initEnable ){
If (B ){
This. enable ();
}
Else {
This. disable ();
}
}
Else {
This. disable ();
}
}
});
Example 2:
Copy codeThe Code is as follows:
Ext. define ('po _ Head_Add_Panel ',{
Extend: 'ext. form. Panel ',
Alias: 'widget. PO_Head_Add_Panel ',
// Height: 400,
// Width: 600,
Frame: true,
Layout: 'anchor', // This form is divided into two columns
BodyPadding: 5, // offset 5px
// BaseCls: "x-plain", // specify the system background color
// Defaults: {anchor: "95%", msgTarget: "side "},
// Anchor: '123 ',
Defaults: {// set the default attributes of all form fields
// AutoFitErrors: false, // whether to automatically adjust the width of the field component when the error message is displayed
LabelSeparator: ', // delimiter
LabelWidth: 60, // label width
// Width: 150, // field width
AllowBlank: false, // whether to allow null
// BlankText: 'cannot be blank ', // if it is not set to null, the prompt is displayed.
LabelAlign: 'right', // tag alignment Mode
MsgTarget: 'qtip '// displays a floating prompt.
// MsgTarget: 'title' // displays the original floating prompt information of a browser.
// MsgTarget: 'under' // a prompt is displayed below the field
// MsgTarget: 'day' // a prompt is displayed on the right of the field
// MsgTarget: 'none' // No prompt is displayed
// MsgTarget: 'errormsg '// display the prompt information in the errorMsg Element
},
Items :[{
Xtype: 'combobox ',
Name: 'toaddress ',
LabelWidth: 70,
Width: 600,
QueryMode: 'local ',
Store: TmpAddressStore,
DisplayField: 'addrname ',
ValueField: 'addrname ',
Editable: false, // whether input is allowed
ForceSelection: true, // You must select an option
MsgTarget: 'day ',
AllowBlank: false, // whether null values are allowed
FieldLabel: 'shipping address'
},{
Xtype: 'textfield ',
Name: 'hremark ',
LabelWidth: 70,
Width: 600,
MsgTarget: 'day ',
AllowBlank: false, // whether null values are allowed
FieldLabel: 'note'
}],
InitComponent: function (){
Var me = this;
Var PoType = ''; // you can use the property obj. PoType.
Var TmpHeadRec = Ext. create ('po _ headdata ');
Ext. apply (this ,{
Buttons :[{
Text: 'save ',
Handler: function (){
If (me. getForm (). isValid () {// checks whether the submitted data conforms to the regular expression.
// Save
}
}
},{
Text: 'cancel ',
Handler: function (){
Me. ownerCt. hide ();
}
}],
SetFormValue: function () {// call the custom method obj. SetFormValue ()
Me. TmpHeadRec = HeadStore. getAt (0 );
Me. getForm (). findField ('potype'). setValue (me. TmpHeadRec. get ('potype '));
Me. getForm (). findField ('ponum'). setValue (me. TmpHeadRec. get ('ponum '));
}
});
This. callParent (arguments );
}
});