ExtJS a tutorial on passing parameters between pages

Source: Internet
Author: User
Tags extend

 extjs How to transfer parameters between different pages, for many novice is a big problem, Lee bad at the beginning of the use of ExtJS is all kinds of to no avail, the beginning of Lee bad in the need to pass the parameters of the case is to use global variables to achieve, the Earth people know, Global variables are flooded, and for a slightly larger project, it's definitely a problem at the end of the spectrum. After a variety of groping and inspection, Lee Bad found using the Ext.create method can be a perfect solution to this problem, here gives a simple case, to provide you with a way of thinking.
Case Description:
      1. Set up a tree menu (Treepanel)
      2. Right-click on the Tree menu node (for example: Node A), pop-up menu
      3. When you click the button on the right menu, get the node information on the a node
       Treepanel and right-click menu as two different Views (page), through the above three steps can be treepanel on the node information, passed to the menu, the following gives the specific implementation code.

The code is as follows Copy Code

Ext.define (' Demo.view.Viewport ', {
Extend: ' Ext.container.Viewport ',
items:[{
Xtype: ' Treepanel ',
Alias: ' Widget.treepanel ',
Title: ' Pass parameters between pages ',
HEIGHT:500,
width:600,
Margin: ' 100 0 0 500 ',
Displayfield: ' Text ',
Rootvisible:false,
Store: ' Treestore '
}]
});

Menu View:

The code is as follows Copy Code

Ext.define (' Demo.view.Menu ', {
Extend: ' Ext.menu.Menu ',
Alias: ' Widget. Menu ',
items:[{
Text: ' Add ',
Action: ' Add '
},{
Text: ' Delete ',
Action: ' del '
},{
Text: ' Edit ',
Action: ' Edit '
}]
})

Controller (Controller):

The code is as follows Copy Code

Ext.define (' Demo.controller.DemoController ', {
Extend: ' Ext.app.Controller ',
Views: [' Menu '],
Stores: [' Treestore '],

Init:function () {
This.control ({
' Treepanel ': {
Itemcontextmenu:this. ShowContextMenu
},
' Menu [Action=add] ': {
Click:this. Clickaddbutton
}
})
},

Showcontextmenu:function (view, REC, item, index, e) {
E.preventdefault ();
E.stopevent ();
This is the key.
Ext.create (' widget. Menu ', {
Rec:rec.data
}). Showat (E.getxy ());
},
Clickaddbutton:function (b,e) {
var text = B.up (). Rec.text;
var id = b.up (). rec.id;
Ext.Msg.alert (' Hint ', ' you click on the node name is ' +text+ ', Node ID is ' +id ');
}
});

Dd

Effect Illustration:
      1. Tree menu icon

      2. Right-click menu icon

      3. Click the Add button after the icon

       as shown in the figure, When we click on the Add button, we can successfully get the node information on the Treepanel.
Parameters:
       Using the Ext.create method to implement the key points of the argument, when we instantiate the menu view with the Create method, we pass the required parameters as an attribute (we are rec here) to the menu instance, so that we can get the required parameters in the menu. Of course, the parameter passing between other views can also be implemented in this way.
       above the method is only ExtJS in the application of their own commonly used in a mode of reference, if there is a better way to achieve, but also hope that the great God will not hesitate to enlighten!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.