How to expand a specific item in the accordion layout of ExtJS

Source: Internet
Author: User

How to expand a specific item in the accordion layout of ExtJS

As required by the project, extJS is used as the front-end framework of the background management system.
As we all know, the background management system generally displays menus Based on permissions.
The menu uses the accordion layout of the panel, and then uses the panel to enclose a tree (treepanel ).
It is inconvenient to refresh, because you want to automatically open the expanded menu of the last time.
The key points are as follows:
1. Use Cookies or the LocalStorage of HTML5 to remember the last menu-expanded rootID.
2. Call the expand () method of the accordion layout neutron element panel.
Some codes in Controller are as follows:

// Load the menu loadMenuResources according to the permission: function (view) {// obtain data from the store Using ajax var _ self = this; // var last_menu_index = 0; // create a tree var tree = _ self. createTree (ESSM. resoures); // Add menu var menuArray = []; Ext. array. each (tree, function (root, index) {// if (root. id) {var last_menu_id = getCookie ("last_menu_id"); if (root. id = last_menu_id) {last_menu_index = index ;}// menuArray. push ({title: root ['text'], autoScroll: true, items: {xtype: 'treepanel ', rootVisible: false, lines: false, border: false, autoScroll: 'none', store: _ self. createTreeStore (root), listeners: {itemclick: function (view, record, item, index, e, eOpts) {// select a menu event // create a controller to display the current content _ self. createController (_ self, record. get ('id'), record. get ('text'), record); // if no error occurs, cache root. id setCookie ("last_menu_id", root. id) ;}}}) ;}; view. add (menuArray); // expandLastMenu (); function expandLastMenu () {// expand the last loaded menu // var last_menu_id = getCookie ("last_menu_id "); // fireEvent // expand try {(view. items. items [last_menu_index]. expand ();} catch (ex) {// eat }};}

Of course, the code is ugly. The key is the expandLastMenu () method. In fact, the logic is very simple. eapand () can be used, and the EXT source code is not involved.
In addition, the two tool methods (reading and writing cookies) are as follows:

/*************************************** ********************* ******************************* // Obtain the cookie value (key) function getCookie (cookieName) {// obtain the cookie string var strCookie = document. cookie; // cut multiple cookies into multiple names/value pairs var arrCookie = strCookie. split (";"); var cookieValue = null; // traverses the cookie array and processes each cookie pair for (var I = 0; I

Related Article

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.