8. Teach you Ext5 (eight) Customize menu 2

Source: Internet
Author: User

This section defines three different types of menu classes. First define the menu button class. The file is placed under the App/view/main/region directory, and the file name is buttonmainmenu.js.

/**/ext.define (' App.view.main.region.ButtonMainMenu ', {    ' App.ux.ButtonTransparent ',    ' Widget.buttonmainmenu ',    ' main ',    ' menu ' ,     0xf0c9,    function  () {        This]. Getviewmodel (). Getmenus ();          This . Callparent ();    }})

The second tree-like menu with the file name Mainmenutree.js.

/** * Tree menu, displayed on the left side of the main screen*/Ext.define (' App.view.main.region.MainMenuTree ', {extend:' Ext.tree.Panel ', alias:' Widget.mainmenutree ', Title:' System Menu ', Glyph:0xf0c9, rootvisible:false, lines:true, ViewModel:' Main ', InitComponent:function () {         This. store = ext.create (' Ext.data.TreeStore ', {root: {text:' System Menu ', Leaf:false, expanded:true            }        }); varMenus = This. Getviewmodel (). Get (' Systemmenu '); varRoot = This. Store.getrootnode ();  for(varIinchmenus) {            varMenugroup =Menus[i]; varMenuItem =Root.appendchild ({text:menugroup.text, expanded:menugroup.expanded, I            Con:menugroup.icon, glyph:menugroup.glhpy});  for(varJinchmenugroup.items) {varMenumodule =Menugroup.items[j]; varChildnode ={moduleId:menumodule.text, moduleName:menumodule.module, Text:menumodule.text, Leaf:true                };            Menuitem.appendchild (Childnode); }        }         This. Callparent (arguments); }})

The third type is a folding menu, with the file name Accordionmainmenu.js.

/** * Folding (Accordion) menu, style can be used to beautify their own CSS*/Ext.define (' App.view.main.region.AccordionMainMenu ', {extend:' Ext.panel.Panel ', alias:' Widget.mainmenuaccordion ', Title:' System Menu ', Glyph:0xf0c9, layout: {type:' Accordion ', animate:true}, ViewModel:' Main ', InitComponent:function () {         This. Items = []; varMenus = This. Getviewmodel (). Get (' Systemmenu ');  for(varIinchmenus) {            varMenugroup =Menus[i]; varAccpanel ={menuaccordion:true, Xtype:' Panel ', Title:menugroup.text, bodystyle: {padding:' 10px '}, Layout:' Fit ', Dockeditems: [{dock:' Left ', Xtype:' Toolbar ', items: []}], glyph:menugroup.glyph};  for(varJinchmenugroup.items) {varMenumodule =Menugroup.items[j]; accpanel.dockeditems[0].items.push ({xtype:' Buttontransparent ', Text: This. Addspace (Menumodule.text, 12), Glyph:menumodule.glyph, Handler:' Onmainmenuclick '                }); }             This. Items.push (Accpanel); }         This. Callparent (arguments); }, Addspace:function(text, len) {console.log (text.length); varresult =text;  for(vari = text.length; i < Len; i++) {result+ = "; }        returnresult; }})

Add these three types of menus to the page. First modify the Top.js, introduce the button menu class

Uses: [' app.ux.ButtonTransparent ', ' App.view.main.region.ButtonMainMenu '],

Then add the items in the

{    ' Buttonmainmenu '}

Modify Main.js, introduce Mainmenutree and Accordionmainmenu, add in Items

{      ' mainmenutree ',      //  left panel      width:250,        True  }, {      ' mainmenuaccordion ',      //  left panel      width:250,      true  },  

After the above processing, there are now 4 types of menus on the interface. See:

8. Teach you Ext5 (eight) Customize menu 2

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.