In the client system, or in any system, the same operation can be triggered in different ways. For example, if you use a browser to refresh the current page, you can click the refresh button, you can choose to refresh from the shortcut menu or press the F5 shortcut key. However, no matter how the operation method changes, the operation itself remains unchanged, so we can abstract these operations.
See the followingCode:
1:Srims. Action =New Function(){
2:};
3:
4:Srims. Action. doaction =Function(E, T ){
5:E. stopevent ();
6:VaRActionname = T. Id. Replace ('Menubaritem--','');
7:
8:If(! Srims. Action. Actions [actionname]) {
9:Alert ('Sorry, this function has not been implemented yet. ');
10:Return;
11:}
12:
13:Srims. Action. Actions [actionname] ();
14:};
15:
16:Srims. Action. Actions = {
17:'Project-Vertical-list':Function(){
18:Srims. Action. _ callprojectaction ('Srims. Projects. listverticalproject ();');
19:},
20:'Project-horizontal-list':Function(){
21:Srims. Action. _ callprojectaction ('Srims. Projects. listhorizontalproject ();');
22:}
23:};
24:
25:Srims. Action. _ callprojectaction =Function(FN ){
26:If(Srims. Projects ){
27:Eval (FN );
28:}
29:Else{
30:Srims. loadprojectmodule (FN );
31:}
32:}
The above code is using extjs to develop MIS System (2): JS dynamic loading has occurred. This Code defines all operations in the system through srims. Action. Actions, and calls the operation through srims. Action. doaction. Srims. Action. doaction accepts two parameters. The first parameter is the parameter of the click event, and the second parameter is the element that inspires the click operation. If the element ID that inspires the operation has a certain relationship with the corresponding operation, you can directly map it to an operation. For example, we bind srims. Action. doaction to the following html
< Ul Class = "" > < Li ID = "Menubaritem-li-project-Vertical-list" > < A ID = "Menubaritem-a-project-Vertical-list" Class = "" Href = "#" > Vertical project list </ A > </ Li > < Li ID = "Menubaritem-li-project-horizontal-list" > < A ID = "Menubaritem-a-project-horizontal-list" Class = "" Href = "#" > Horizontal project list </ A > </ Li > </ Ul >
The correspondence between the ID of tag a and the operation name is prefixed with "menubaritem-a-" before the operation name, so we use this in srims. Action. doaction.VaRActionname = T. Id. Replace ('Menubaritem--','') After the prefix is replaced, you can get the corresponding operation name, and then you can call srims. Action. Actions [actionname] () to execute this operation. You can also use
If(! Srims. Action. Actions [actionname]) {alert ('Sorry, this function has not been implemented yet. ');Return;}
Check whether the operation has been completed.
The binding operation uses the event handling method in extjs. The sample code is as follows:
var AB = srims. menubar. getmenubar (). body; AB. on ( 'mousedown' , srims. action. doaction, null , { DeleGate : 'A' }); AB. on ( 'click' , ext. emptyfn, null , { DeleGate : 'A' , preventdefault: true });
The biggest advantage of abstracting operations in one place is that operations can be controlled in a unified manner, which is used to develop MIS Systems Using extjs (2): Dynamic Loading of JS is used, in the above Code, this feature is also used when processing unimplemented operations.