`

[ExtJS2.1教程-2]组件的使用

    博客分类:
  • ext
阅读更多
我们还是以alert为例
首先我们如果想创建一个alert 可以先去文档中查看
Ext.MessageBox包下
文档中我们可以看到一些demo
和属性 方法 事件的介绍。
这里只存在属性和方法
alert( String title, String msg, [Function fn], [Object scope] ) : Ext.MessageBox 
Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt). If a c...
Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt). If a callback function is passed it will be called after the user clicks the button, and the id of the button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button). 
Parameters:
 
title : String
The title bar text
msg : String
The message box body text
fn : Function
(optional) The callback function invoked after the message box is closed
scope : Object
(optional) The scope of the callback function
Returns:
 
Ext.MessageBox
this

这就是alert方法的介绍 很详细
下面我们想要一个有警告框的alert
我们在方法中发现了一个show方法 接受的参数是配置选项(属性)
直接用样例代码
Ext.onReady(function() {
	// Ext.Msg.alert("hello");
	Ext.Msg.show({
		title : 'Save Changes?',
		msg : 'You are closing a tab that has unsaved changes. Would you like to save your changes?',
		buttons : Ext.Msg.YESNOCANCEL,
		// fn: processResult,
		animEl : 'elId',
		//警告图标
		icon : Ext.MessageBox.WARNING
	})

});


可以在属性介绍中看到描述是"The CSS class that provides the INFO icon image",来替换icon的样式 即图标样式
对于按钮的样式也可以改变"Button config that displays a single OK button "具体使用同上

对于组件来说主要有三大类:基本组件、工具栏组件、表单及元素组件
Component是顶级组件 及 其它组件是由他进行定义的 每一个组件都有一个xtype属性值,该值可以知道一个组件类型或者说是定义一个该类型的组件
xtype            Class
-------------    ------------------
box              Ext.BoxComponent
button           Ext.Button
colorpalette     Ext.ColorPalette
component        Ext.Component
container        Ext.Container
cycle            Ext.CycleButton
dataview         Ext.DataView
datepicker       Ext.DatePicker
editor           Ext.Editor
editorgrid       Ext.grid.EditorGridPanel
grid             Ext.grid.GridPanel
paging           Ext.PagingToolbar
panel            Ext.Panel
progress         Ext.ProgressBar
propertygrid     Ext.grid.PropertyGrid
slider           Ext.Slider
splitbutton      Ext.SplitButton
statusbar        Ext.StatusBar
tabpanel         Ext.TabPanel
treepanel        Ext.tree.TreePanel
viewport         Ext.Viewport
window           Ext.Window

Toolbar components
---------------------------------------
toolbar          Ext.Toolbar
tbbutton         Ext.Toolbar.Button
tbfill           Ext.Toolbar.Fill
tbitem           Ext.Toolbar.Item
tbseparator      Ext.Toolbar.Separator
tbspacer         Ext.Toolbar.Spacer
tbsplit          Ext.Toolbar.SplitButton
tbtext           Ext.Toolbar.TextItem

Form components
---------------------------------------
form             Ext.FormPanel
checkbox         Ext.form.Checkbox
combo            Ext.form.ComboBox
datefield        Ext.form.DateField
field            Ext.form.Field
fieldset         Ext.form.FieldSet
hidden           Ext.form.Hidden
htmleditor       Ext.form.HtmlEditor
label            Ext.form.Label
numberfield      Ext.form.NumberField
radio            Ext.form.Radio
textarea         Ext.form.TextArea
textfield        Ext.form.TextField
timefield        Ext.form.TimeField
trigger          Ext.form.TriggerField


我们可以看到每一个xtype代表一个组件,可以清楚的看到三大类的分割
我们来建一个panel
Ext.onReady(function() {
	var panel = new Ext.Panel({
		title:"this panel",
		width:200,
		height:300,
		html:"hello world"
	});
	panel.render("hello");

});

这里我们通过render方法进行渲染得到的。
Ext.onReady(function() {
	var panel = new Ext.Panel({
		renderTo:"hello",
		title:"this panel",
		width:200,
		height:300,
		html:"hello world"
	});
	//panel.render("hello");

});

我们也可以通过renderTo属性直接进行渲染

xtype是指定组件类型
下面我们以tabpanel为例
var tp = new Ext.TabPanel({
		renderTo:"hello",
		width:300,
		height:300,
		activeItem:0,
		items:[{
			title:"this panel1",
			html:"hello world1"
		},{
			title:"this panel2",
			html:"hello world2"
		},new Ext.tree.TreePanel({
			title:"tree panel",
			loader:new Ext.tree.TreeLoader(),
			root:new Ext.tree.AsyncTreeNode({
				text:"根节点",
				children:[{
					text:"叶子1",
					leaf:true
				},{
					text:"叶子2",
					leaf:true
				}]
			})
		}),{
			title:"tree panel2",
			loader:new Ext.tree.TreeLoader(),
			root:new Ext.tree.AsyncTreeNode({
				text:"根节点",
				children:[{
					text:"叶子1",
					leaf:true
				},{
					text:"叶子2",
					leaf:true
				}]
			}),
			xtype:"treepanel"
		}]
	})

activeItem:0表示第几个items是活动状态
items:Mixed (数组类型)
还有一点需要注意的是items可以放数组,如果只有一个也可以直接使用对象方式 如{}或new
看到最后一个treepanel了吗 我们是采用xtype来告诉panel当前组件的类型,由于第一第二各tab是标准panel所以不用显示指明(tp items下默认如此),第三第四个则需要显示指明
如果第四个不加xtype 将按panel进行解析 由于没有html所以显示为空
为什么会是这样的呢 可以看一下Container(容器组件,所有容器组件的父类 如panel)其父类是BoxComponent(包含长宽高)

分享到:
评论

相关推荐

    extJs 2.1学习笔记

    24. extJs 2.0学习笔记(组件总论篇) 66 25. extJs 2.0学习笔记(Ext.Element API总结) 69 26. extJs 2.0学习笔记(Element.js篇) 73 27. extJs 2.0学习笔记(DomHelper.js篇) 76 28. extJs 2.0学习笔记(ext.js篇) 77

    ExtJS 3.0 调用 swfupload 制作的多附件上传组件,带进度条

    ExtJS 2.1~3.x 调用 swfupload 制作的多附件上传组件,带进度条,列表为gridpanel

    ExtJS-3.4.0系列目录

    一、基础篇 1、Ext JS下载及配置 2、基本功能  2.1、Ext.MessageBox消息框  2.2、Ext.window.MessageBox 3、工具栏和菜单栏  3.1、Ext.toolbar.Toolbar工具栏  3.2、Ext.menu.Menu菜单栏 4、表单

    精通JS脚本之ExtJS框架.part2.rar

    本书共分17章,分别介绍了JavaScript的对象编程、JavaScript浏览器对象模型和事件机制、ExtJS的核心类库和组件、ExtJS的事件处理方式、设计进度条、设计工具栏和菜单栏、设计面板、设计表格、设计表单、设计数据表、...

    深入浅出ExtJS第2版

    深入浅出ExtJS第2版+源码..1 下载EXT发布包 1 1.2 如何查看EXT自带的API和示例 1 1.3 为什么有些示例必须放在服务器上 才能看到效果 2 1.4 Hello World 2 1.4.1 直接使用下载的发布包 2 1.4.2 在项目中使用EXT...

    ExtJSWeb应用程序开发指南(第2版)

    2.1 认识ExtJS的开发包 2.2 也从Helloworld开始 2.3 ExtJS中的基本概念 2.4 非常有用的开发工具 2.4.1 开发插件spket 2.4.2 FullSource 2.4.3 MicrosoftScriptDebugger 2.5 ExtJS对原有JavaScript对象的扩展 ...

    ExtJs2.0简明教程

    ……..8 2.2 ExtJS的组件………………………………………………………………………………………………………...9 2.3 组件的使用………………………………………………………………………………………………...

    SenchaArchitect-2.1

    通过拖拽组件来创建富用户界面并连接到后端的数据源。 支持通过Sencha Touch 2来构建移动Web应用以及通过Ext JS 4来构建桌面Web应用。 其提供的代码编辑功能可以在Sencha Architect中创建整个应用。 支持模型——...

    精通JS脚本之ExtJS框架.part1.rar

    本书共分17章,分别介绍了JavaScript的对象编程、JavaScript浏览器对象模型和事件机制、ExtJS的核心类库和组件、ExtJS的事件处理方式、设计进度条、设计工具栏和菜单栏、设计面板、设计表格、设计表单、设计数据表、...

    log4Net详解(共2讲)

    2、ExtJs进阶篇:主要介绍ExtJs里的常用组件,容器及布局 3、ExtJs数据篇:主要介绍和数据库交互的相关组件及CRUD功能 4、项目实战篇: Extjs3.2+ASP.NET七层架构+设计模式+ log4j+WebSerice等技术国讯教育通用...

    Ext Js权威指南(.zip.001

    Ex4.0共2个压缩包特性,《ext js权威指南》 前 言 第1章 ext js 4开发入门 / 1 1.1 学习ext js必需的基础知识 / 1 1.2 json概述 / 3 1.2.1 认识json / 3 1.2.2 json的结构 / 3 1.2.3 json的例子 / 4 1.2.4 ...

Global site tag (gtag.js) - Google Analytics