Ext Js简单常用对象的创建使用

简介:

Ext Js简单常用对象的创建使用

在自己的随笔中关于Ext Js的文章是针对Ext Js的3.4.0版的API脚本库。

1.对于alert和prompt的创建使用

复制代码
function TestMsg() {
    //可以比较一下显示效果
    //alert(confirm("是否确认退出?"));
    //Ext.MessageBox.alert("消息", "ExtJs提示框");
    
    Ext.Msg.alert("信息提示", "这样处理是否成功?", function () { alert('TT!') });
    //弹出输入内容的对话框
    Ext.Msg.prompt("AA", "PSPSPSPS", function (btn, text) {
        if (btn == "ok") {
            alert(text);
        }
        else {
            alert("Not:" + text);
        }
    });
}
复制代码

2.对于Ext.MessageBox.show的创建使用

复制代码
function TTMsgShow() {
    Ext.MessageBox.show({
        title: '提示',
        msg: '信息内容显示',
        width: 400,
        icon: Ext.MessageBox.QUESTION, //ERROR\INFO\WARNING\QUESTION
        buttons: Ext.MessageBox.YESNOCANCEL,//YESNOCANCEL\OKCANCEL
        animate: true, //是否有动画效果
        multiline: true, //显示输入的多行数据
        //buttons: { "yes": "<h2>yeah!<h2/>", "no": "<h2>oh no!<h2/>", "cancel": "<h2>X<h2/>" },//自定义的buttons显示
        fn: function (btn) {
            switch (btn) {
                case 'ok': Ext.MessageBox.alert('信息提示', '你点的是'+btn+'按钮'); break;
                case 'cancel': Ext.MessageBox.alert('信息提示', '你点的是Cancel按钮'); break;
                case 'yes': Ext.MessageBox.alert('信息提示', '你点的是YES按钮'); break;
                case 'no': Ext.MessageBox.alert('信息提示', '你点的是No按钮'); break;
                default:Ext.MessageBox.alert('信息提示', '你点的是'+btn+'按钮'); break;
            }
        }
    });
}
复制代码

3.对于ToolTip的创建使用

复制代码
//简单ToolTip一些效果配置
function toolTipTest() {
    new Ext.ToolTip({
        target: 'divTest', //指向区域 
        title: 'TT',
        closable: true, //是否关闭显示
        autoHide: false, //是否自动隐藏
        draggable: true, //是否随意拖放
        showDelay: 10, //显示延迟,默认500
        trackMouse: true, //鼠标划过,随鼠标移动
        html: '<h1>测试信息学想你想你想你想</h1>'
    }).show();
}
//简单ToolTip显示位置配置
function toolTipTT() {
    new Ext.ToolTip({
        target: 'divTest', //指向区域 
        title: '<a href="#">ToolTip Title<\a>',
        closable: true, //是否关闭显示
        autoHide: false, //是否自动隐藏
        anchor: 'top', //位置为top\buttom\right
        anchorOffset: 50, //位置偏移量
        contentEl: 'tipContent', //一个已存在的HTML元素,或者一个已存在HTML元素的 id 
        html: '<h1>测试信息学想你想你想你想</h1>'
    }).show();
}
复制代码

4.对于Window的创建使用

复制代码
//简单window页面
function getTestWin() {
    var win = new Ext.Window({
        title: "ExtWindow",
        width: 300,
        height: 500,
        renderTo:Ext.getBody(),
        html: '<h1><font>Hello ExtJS!</font></h1>',
        items:
            [
                new Ext.Button({ text: "通过New Button添加的对象" }),
                new Ext.Button({ text: "items下添加2个New Button" }),
                { xtype: "button", text: "通过xtype设置属性新Button" },
                { xtype: "colorpalette", width: 150, height: 100 }
            ]
    });
    win.show();
}
复制代码

5.对于FormPanel的创建使用(对于表单一些常用对象的创建也在里面了)

复制代码
//创建表单
function createForm() {
    //初始化单例。任何基于标签的快速提示开始工作。
    Ext.QuickTips.init(); //初始化所有quickTips的所有提示信息

    var fromTest = new Ext.FormPanel({
        layout: 'form', autoHeight: true, frame: true, renderTo: Ext.getBody(), width: 300, height: 500, //frame是否渲染表单
        title: '<center bgcolor="Yellow" onclick="window.location.reload()">表单练习</center>',
        style: 'margin-left:auto,margin-top:50px,width:500px,background-color: Yellow',
        labelAlign: 'left', labelWidth: 80, buttonAlign: 'center', defaults: { width: 180 }, //标签对齐方式、标签宽度、元素对齐、默认属性
        items: [
                    { xtype: 'textfield', fieldLabel: '文本框控件', id: 'txtContent', name: 'TextBox' },
                    { xtype: 'textfield', fieldLabel: '文本框', id: 'txt', readOnly: true, emptyText: '请输入内容' }, //allowDecimals:允许小数;allowNegative:允许负数
                    {xtype: 'numberfield', fieldLabel: '输入数字', id: 'txtNum', allowDecimals: false, allowNegative: false, maxValue: 1000, minValue: 0 },
                    { xtype: 'combo', fieldLabel: '下拉框控件', id: 'combTest', mode: 'local', displayField: 'Name', valueField: 'Id', editable: false,
                        typeAhead: true, forceSelection: false, triggerAction: 'all', selectOnFocus: true, //forceSelection:必选一项;triggerAction:匹配所有
                        store: new Ext.data.SimpleStore({ fields: ['Id', 'Name'], data: [['1', '李白'], ['2', '李杜'], ['3', '李丽']] })
                    },
                    { xtype: 'datefield', fieldLabel: '日历控件', id: 'dateTest', format: 'Y-m-d', editable: false, value: new Date().format('Y-m-d') }, //默认日期
                    {xtype: 'radiogroup', fieldLabel: '单选按钮', id: 'rabs', name: 'Radios', width: 100,
                    items: [
                    { name: 'Radios', boxLabel: '嫁人', inputValue: '1', checked: true },
                    { name: 'Radios', boxLabel: '娶人', inputValue: '0' }
                    ]
                },
                { xtype: 'checkboxgroup', fieldLabel: '复选控件', columns: 2,//复选框组
                    items: [
                    { boxLabel: '香蕉', inputValue: 'A', id: 'chekA' },
                    { boxLabel: '苹果', inputValue: 'B', id: 'checkB' },
                    { boxLabel: '橘子', inputValue: 'C', id: 'checkC' },
                    { boxLabel: '桃子', inputValue: 'D', id: 'checkD' }
                    ]
                },
                { xtype: 'timefield', fieldLabel: '时间控件', format: 'H:i', increment: 60, value: new Date().toLocaleTimeString() },
                { xtype: 'fieldset', fieldLabel: '标签页', autoHeight: true,//标签页
                    items: [{ xtype: 'panel', title: '标签1', frame: true, height: 50 }, { xtype: 'panel', title: '标签2', frame: true, height: 30}]
                },
                { xtype: 'htmleditor', fieldLabel: '在线编辑器', width: 200, height: 100 }//在线编辑器
                ],
        buttons: [
                { text: '保存', tooltip: '这是保存按钮', handler: function () { Msg('保存成功') } },//tooltip提示信息
                { text: '取消', tooltip: '这是取消按钮', handler: function () { form1.form.reset(); } }
                ]
    });
}
复制代码

6.对于Panel的创建使用

复制代码
function createPanel() {
    var objPro = { title: "Hello Pannel", width: 300, height: 300, html: '<h1>Hello Pannel Source!</h1>' };
    var panel = new Ext.Panel(objPro);
    panel.render("Hello Pannel"); //将面板渲染到Hello Pannel处,为Div的id
    //此处的render方法后面的参数表示页面上的div元素id,也可以直接通过属性renderTo参数来替换render方法,也可以renderTo:Ext.getBody()
    //例如:new Ext.Panel({renderTo:"hello",title:"Hello Panel",width:300,height:300,html:'<h1>Hello Panel Source!</h1>'});

    //对于一个容器控件(组件),支持延迟方式创建子控件,在父控件的items属性来传递数组方式构建
    //例如:var tabPanel=new Ext.TabPanel({width:200,height:300;items:[
    //{title:"面板1",height:30},{title:"面板2",height:30},{title:"面板3",height:30}
    //]});    
    //等价于:var tabPanel=new Ext.TabPanel({width:200,height:300,items[
    //new Ext.Panel({title:"面板1",height:30}),new Ext.Panel({title:"面板2",height:30},new Ext.Panel({title:"面板3",height:30}))
    //]});
    //相比而言,前者较好,前者是在初始化时创建的;后者是一开始就创建,前者实现了延迟加载
}
复制代码

7.API文档中对于“xtype”的介绍

复制代码
以下是所有的'xtype'和类的对应关系 
xtype            Class
-------------    ------------------
box              Ext.BoxComponent
button           Ext.Button
buttongroup      Ext.ButtonGroup
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
flash            Ext.FlashComponent
grid             Ext.grid.GridPanel
listview         Ext.ListView
panel            Ext.Panel
progress         Ext.ProgressBar
propertygrid     Ext.grid.PropertyGrid
slider           Ext.Slider
spacer           Ext.Spacer
splitbutton      Ext.SplitButton
tabpanel         Ext.TabPanel
treepanel        Ext.tree.TreePanel
viewport         Ext.ViewPort
window           Ext.Window

Toolbar components
---------------------------------------
paging           Ext.PagingToolbar
toolbar          Ext.Toolbar
tbbutton         Ext.Toolbar.Button        (过时的;使用 button)
tbfill           Ext.Toolbar.Fill
tbitem           Ext.Toolbar.Item
tbseparator      Ext.Toolbar.Separator
tbspacer         Ext.Toolbar.Spacer
tbsplit          Ext.Toolbar.SplitButton   (过时的;使用 splitbutton)
tbtext           Ext.Toolbar.TextItem

Menu components
---------------------------------------
menu             Ext.menu.Menu
colormenu        Ext.menu.ColorMenu
datemenu         Ext.menu.DateMenu
menubaseitem     Ext.menu.BaseItem
menucheckitem    Ext.menu.CheckItem
menuitem         Ext.menu.Item
menuseparator    Ext.menu.Separator
menutextitem     Ext.menu.TextItem

Form components
---------------------------------------
form             Ext.form.FormPanel
checkbox         Ext.form.Checkbox
checkboxgroup    Ext.form.CheckboxGroup
combo            Ext.form.ComboBox
datefield        Ext.form.DateField
displayfield     Ext.form.DisplayField
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
radiogroup       Ext.form.RadioGroup
textarea         Ext.form.TextArea
textfield        Ext.form.TextField
timefield        Ext.form.TimeField
trigger          Ext.form.TriggerField

Chart components
---------------------------------------
chart            Ext.chart.Chart
barchart         Ext.chart.BarChart
cartesianchart   Ext.chart.CartesianChart
columnchart      Ext.chart.ColumnChart
linechart        Ext.chart.LineChart
piechart         Ext.chart.PieChart

Store xtypes
---------------------------------------
arraystore       Ext.data.ArrayStore
directstore      Ext.data.DirectStore
groupingstore    Ext.data.GroupingStore
jsonstore        Ext.data.JsonStore
simplestore      Ext.data.SimpleStore      (过时的;使用 arraystore)
store            Ext.data.Store
xmlstore         Ext.data.XmlStore
复制代码

是不是应该加上一些截图看看效果呢?自己不太喜欢写很长的文章尽量缩减,因为太长的话,大家都会没有耐心看下去的,虽这样不是很好,但也考虑一些大家感受。想想如果把代码注释的足够详细,那么将更容易让人理解了。只有效果截图,而没有代码注释,这样的代码就相当于不写,可读性不好,别人不明白你写的是什么,良好的注释还是有必要的。


本文转自SanMaoSpace博客园博客,原文链接:http://www.cnblogs.com/SanMaoSpace/archive/2013/01/23/2873787.html,如需转载请自行联系原作者

相关文章
|
8天前
|
JavaScript
JS 获取对象数据类型的键值对的键与值
JS 获取对象数据类型的键值对的键与值
|
18天前
|
JavaScript 前端开发
Math对象:JavaScript中的数学工具
Math对象:JavaScript中的数学工具
26 1
N..
|
25天前
|
存储 JavaScript 前端开发
JavaScript中的对象
JavaScript中的对象
N..
10 0
|
11天前
|
JavaScript 算法
原生JS完成“一对一、一对多”矩形DIV碰撞检测、碰撞检查,通过计算接触面积(重叠覆盖面积)大小来判断接触对象DOM
原生JS完成“一对一、一对多”矩形DIV碰撞检测、碰撞检查,通过计算接触面积(重叠覆盖面积)大小来判断接触对象DOM
|
3天前
|
JavaScript
【Js】检查Date对象是否为Invalid Date
【Js】检查Date对象是否为Invalid Date
6 0
|
3天前
|
存储 JavaScript 前端开发
JavaScript的引用数据类型主要包括对象
【4月更文挑战第16天】JavaScript的引用数据类型主要包括对象
16 4
|
8天前
|
JavaScript
js 字符串String转对象Object
该代码示例展示了如何将一个以逗号分隔的字符串(`&#39;1.2,2,3,4,5&#39;`)转换为对象数组。通过使用`split(&#39;,&#39;)`分割字符串并`map(parseFloat)`处理每个元素,将字符串转换成浮点数数组,最终得到一个对象数组,其类型为`object`。
|
16天前
|
存储 JavaScript 前端开发
在浏览器中存储数组和对象(js的问题)
在浏览器中存储数组和对象(js的问题)
|
26天前
|
存储 JavaScript 索引
js开发:请解释什么是ES6的Map和Set,以及它们与普通对象和数组的区别。
ES6引入了Map和Set数据结构。Map的键可为任意类型,有序且支持get、set、has、delete操作;Set存储唯一值,提供add、delete、has方法。两者皆可迭代。示例展示了Map和Set的基本用法,如添加、查询、删除元素。
13 2
|
29天前
|
JavaScript 前端开发
JavaScript操作BOM对象
JavaScript操作BOM对象
9 1