源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Extjs学习笔记之四 工具栏和菜单

  • 时间:2020-10-18 10:40 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Extjs学习笔记之四 工具栏和菜单
ToolBar的使用很简单,关键是向ToolBar上面添加内容,默认地ToolBar添加的是Button,不过实际上可以向Toolbar添加任意的组件。下面是一个例子:
[url=http://www.extjs.com/source/Component.html#cfg-Ext.Component-xtype]xtype[/url] : String The registered xtype to create. This config option is not used when passing a config object into a constructor. This config option is used only when lazy instantiation is being used, and a child item of a Container is being specified not as a fully instantiated Component, but as a Component config object. Thextype will be looked up at render time up to determine what type of child Component to create. 这句话说的是如果在new的时候使用xtype,这个xtype是忽略的,这个是明显的,用了new就肯定要指定一个类型,xtype是无用的。后面半句才是关键,它的意思是如果使用xtype,对象并不是立刻构造出来的,而是采用一种延迟加载的机制,等到需要显示这个对象的时候再去构造它,在第一次使用之前在内存中仅是一个组件配置对象(component config object),虽然API文档没有明说,但是却暗示出来如果可能,使用xtype而不是new是一个更好的选择,它可以节省内存。实际中,不是所有的组件都需要被显示,那么那些没有被显示的组件就不需要被实例化。 此文中谈到了这点 [url=http://www.1sucai.cn/article/21748.htm]EXT中xtype的含义[/url] . 介绍了下xtype,下面回到工具栏上来,上面的代码的运行效果是: [img]http://files.jb51.net/upload/2010-1/20100107210147252.png[/img]   一个很美观的工具栏就出现了。接下来的工作是为这些按钮添加方法,不过这不是本文的讨论范围,以后再讲。 接下来介绍Menu,Menu和Toolbar是很类似的。Menu上能添加的组件在上面的xtype表中已经列出,直接看一个例子:
[u]复制代码[/u] 代码如下:
<script type="text/javascript"> Ext.onReady(function() { var tb = new Ext.Toolbar({ renderTo: document.body, width: 600, height: 100 }); var filemenu = new Ext.menu.Menu({ shadow: 'frame', items: [{ text: 'New' }, { text: 'Open' }, { text: 'Save' }, "-", { text: 'Export' },{ text: 'Import' } ] }); tb.add({ text: 'File', menu: filemenu }); var dateMenu = new Ext.menu.DateMenu({}); var colorMenu = new Ext.menu.ColorMenu({}); tb.add({ text: 'Colorful', menu: { xtype: 'menu', items: [ {text: 'Choose a date', menu: dateMenu }, { text: 'Choose a color', menu: colorMenu }, "-", { text: 'Radio Options', menu: { // <-- submenu by nested config object items: [ // stick any markup in a menu '<b class="menu-title">Choose a Theme</b>', { text: 'Aero Glass', checked: true, group: 'theme' }, { text: 'Vista Black', checked: false, group: 'theme' }, { text: 'Gray Theme', checked: false, group: 'theme' }, { text: 'Default Theme', checked: false, group: 'theme' } ] } } ]} }); tb.doLayout(); }); </script>
效果如下: [img]http://files.jb51.net/upload/2010-1/20100107210147831.png[/img]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部