Modify the findbytype method of extjs to make up for its shortcomings.

Source: Internet
Author: User

Yesterday I wanted to implement button permission control on the front-end (using extjs). The front-end button permission control itself is not secure and will not be discussed for the moment.

Ext. the findbytype method of the container cannot obtain any types of controls in the lower-level of the container. For example, the get button cannot obtain the buttons in the toolbar of the Panel. Therefore, I want to create a findbytype method myself.

You can use the following method to obtain all the buttons in a container.

// Defines Ext. NS ("TT. util "); Ext. NS ("TT. data "); TT. data. btnarray = NULL; // get all the buttons in the current container TT. util. findbtnbase = function (c) {var array = []; If (C. toolbars) {Ext. each (C. toolbars, function (I) {var J = I. items. items; Ext. each (J, function (k) {If (K. xtype = 'button '| K. type = 'button ') {array. push (k) ;}})});} If (C. items & C. items. items) {var I = C. items. items; Ext. each (I, function (j) {If (J. xtype = 'button '| j. type = 'button ') {array. push (j) ;}}) ;}return array ;}// get all the buttons of the current container and all lower-level containers (recursion) TT. util. findbtn = function (c) {// If C is not a leaf node if (C. items & C. items. items) | (C. toolbars) {var btnarray = TT. util. findbtnbase (c); TT. util. pusharray (btnarray, TT. data. btnarray); If (C. items & C. items. items) {Ext. each (C. items. items, function (I) {TT. util. findbtn (I) ;}}}// extract the contents of the SRC array into the Dest array TT. util. pusharray = function (SRC, DEST) {Ext. each (SRC, function (I) {DeST. push (I );});}

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.