ExtJs4 笔记 Ext.tab.Panel 选项卡

本篇讲解选项卡控件。

一、基本选项卡

首先我们来定义一个基本的选项卡控件,其中每个Tab各有不同,Tab的正文内容可以有三种方式获取:

1.基本方式:通过定义html和items的方式。

2.读取其他html的信息:通过设置contentEl就可以获取其他html的信息为当前tab正文。

3.读取服务端数据:通过定义autoLoad异步方式获取服务端数据。

另外,每个tab都可以设置是否可关闭,进入tab时的事件,以及tab是否可用,具体情况请看代码:

[html]

?
1
2
3
4
5
6
7
8
9
10
<h1>基本选项卡</h1>
<div class="content" style="height: 150px">
    <div id="tabPanel">
        <div style="display: none">
            <div id="oneTab">
                <p>这个tab所展示的内容是读取至其他HTML标签</p>
            </div>
        </div>
    </div>
</div>


[Js]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//1.基本的选项卡
var tabs1 = Ext.createWidget('tabpanel', {
    renderTo: "tabPanel",
    activeTab: 1,                       //指定默认的活动tab
    width: 600,
    height: 120,
    plain: true,                        //True表示tab候选栏上没有背景图片(默认为false)
    enableTabScroll: true,              //选项卡过多时,允许滚动
    defaults: { autoScroll: true },
    items: [{
        id: "tab1",
        title: '普通Tab',
        html: "这只是一个非常普通的Tab。",
        items:[{xtype:'button',text:'按钮'}],
        closable: true                  //这个tab可以被关闭
    }, {
        id: "tab2",
        title: '内容来至div',
        contentEl: 'oneTab'             //指定了当前tab正文部分从哪个html元素读取
    }, {
        id: "tab3",
        title: 'Ajax Tab',
        autoLoad: { url: 'AjaxTabContent', params: { data: "从客户端传入的参数" }, method: 'GET' }
    }, {
        id: "tab4",
        title: '事件Tab',
        listeners: { activate: handleActivate },
        html: "带事件的Tab。"
    }, {
        id: "tab5",
        title: '不可用Tab',
        disabled: true,
        html: "不可用的Tab,你是看不到我的。"
    }]
});
//单击tab4后触发的事件
function handleActivate(tab) {
    alert(tab.title + ': activated事件触发。');
}

 

我们查看一下生成的选项卡效果:

二、操作选项卡

选项卡生成后,我们可以通过js去操作它,比如动态新增、删除、插入选项卡,设置活动选项卡等,我们看看具体实现方法:

[html]

?
1
2
<h1>操作选项卡</h1>
<div class="content" id="content2"></div>


[Js]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var index = 0;
//新增一个Tab
Ext.createWidget("button", {
    text: "新增一个Tab",
    renderTo: 'content2',
    handler: function () {
        tabs1.add({
            title: '新Tab ' + (++index),
            id: "newTab" + index,
            html: '选项卡文本部分 ' + (index) + '<br/><br/>',
            closable: true
        });
    }
});
//插入一个Tab
Ext.createWidget("button", {
    text: "在2号位置插入新Tab",
    renderTo: 'content2',
    handler: function () {
        tabs1.insert(2, {
            title: '新Tab ' + (++index),
            id: "newTab" + index,
            html: '选项卡文本部分 ' + (index) + '<br/><br/>',
            closable: true
        });
    }
});
//删除一个Tab
Ext.createWidget("button", {
    text: "删除2号位置的Tab",
    renderTo: 'content2',
    handler: function () {
        tabs1.remove(2);
    }
});
//删除id为“tab1”的Tab
Ext.createWidget("button", {
    text: "删除id为“tab1”的Tab",
    renderTo: 'content2',
    handler: function () {
        tabs1.remove("tab1");
    }
});
//删除id为“tab1”的Tab
Ext.createWidget("button", {
    text: "设置第三个Tab为活动tab",
    renderTo: 'content2',
    handler: function () {
        tabs1.setActiveTab(2);
    }
});

 

效果:

三、选项卡按钮在下方

默认的选项卡按钮在上方,我们可以随意定义选项卡按钮的位置,下面代码演示了具体的用法:

[html]

?
1
2
<h1>选项卡按钮在下方</h1>
<div class="content" id="content3"></div>


[Js]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//选项卡按钮在下方
var tabs3 = Ext.createWidget('tabpanel', {
    renderTo: "content3",
    activeTab: 0,
    width: 600,
    height: 150,
    tabPosition: 'bottom'           //指定了选项卡的位置,left,right
});
for (var i = 0; i < 3; i++)
    tabs3.add({
        title: 'Tab ' + i,
        id: "Tabs3_" + i,
        html: '选项卡文本部分 ' + (index) + '<br/><br/>',
        closable: true
    });

 

效果:

四、可拖动的选项卡

通过官方扩展包我们可以增强选项卡控件的易用性,比如现在我们可以实现一个可以拖动选项卡按钮的功能:

[html]

?
1
2
<h1>可拖动的选项卡</h1>
<div class="content" id="content4"></div>


[Js]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//首先要动态加载ux扩展的js
Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath('Ext.ux', '/ExtJs/ux');
Ext.require([
    'Ext.tip.QuickTipManager',
    'Ext.tab.Panel',
    'Ext.ux.TabScrollerMenu',
    'Ext.ux.TabReorderer',
    'Ext.ux.TabCloseMenu',
    'Ext.ux.GroupTabPanel'
]);
//以下是功能代码
    //可拖动的选项卡
    var tabs4 = Ext.createWidget('tabpanel', {
        renderTo: "content4",
        activeTab: 0,
        width: 600,
        height: 150,
        plugins: Ext.create('Ext.ux.TabReorderer'),
        items: [{
            xtype: 'panel',
            title: 'tab不可拖',
            html: "这个选项卡不可被拖动",
            reorderable: false,
            closable: true
        }]
    });
    for (var i = 0; i < 3; i++)
        tabs4.add({
            title: 'Tab ' + i,
            id: "Tabs4_" + i,
            html: '选项卡文本部分 ' + (index) + '<br/><br/>'
        });

 

效果如下,可见一个tab已经被移动:

五、过多选项卡的菜单式展示

如果面板上的选项卡打开的过多而显示不下,那么需要对溢出的选项卡用菜单的方式展示出来,实现方式如下,注意要引入扩展的css样式:

[html]

?
1
2
<h1>过多选项卡的菜单式展示</h1>
<div class="content" id="content5"></div>


[Js]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//选项卡过多溢出时菜单显示
var tabs5 = Ext.createWidget('tabpanel', {
    renderTo: "content5",
    activeTab: 0,
    width: 600,
    height: 150,
    plugins: Ext.create('Ext.ux.TabScrollerMenu', {
        maxText: 15,
        pageSize: 5
    }),
    items: [{
        title: 'tab0',
        html: '第一个tab'
    }]
});
Ext.defer(function () {
    var myTabs = [];
    for (var i = 0; i < 15; i++) {
        myTabs.push({
            title: 'Tab ' + i,
            id: "Tabs5_" + i,
            html: '选项卡文本部分 ' + (index) + '<br/><br/>'
        });
    }
    tabs5.add(myTabs);
}, 1000);

 

效果:

六、选项卡的右键菜单

一般的应用程序都支持在选项卡按钮上面通过右键的方式去关闭多余的选项卡,在ext中也可以做到,实现方法如下:

[html]

?
1
2
<h1>选项卡的右键菜单</h1>
<div class="content" id="content6"></div>


[Js]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//选项卡的右键菜单
var currentItem;
var tabs6 = Ext.createWidget('tabpanel', {
    renderTo: "content6",
    activeTab: 0,
    width: 600,
    height: 150,
    plugins: Ext.create('Ext.ux.TabCloseMenu', {
        closeTabText: '关闭当前',
        closeOthersTabsText: '关闭其他',
        closeAllTabsText: '关闭所有',
        extraItemsTail: [
                    '-',
                    {
                        text: '可关闭',
                        checked: true,
                        hideOnClick: true,
                        handler: function (item) {
                            currentItem.tab.setClosable(item.checked);
                        }
                    }
                ],
        listeners: {
            aftermenu: function () {
                currentItem = null;
            },
            beforemenu: function (menu, item) {
                var menuitem = menu.child('*[text="可关闭"]');
                currentItem = item;
                menuitem.setChecked(item.closable);
            }
        }
    }),
    items: [{
        title: 'tab1',
        html: '第一个tab'
    }, {
        title: 'tab2',
        closable: true,
        html: '第二个tab'
    }, {
        title: 'tab3',
        closable: true,
        html: '第三个tab'
    }]
});

 

效果:

七、分组式选项卡

我们还可以对选项卡进行分组,具体实现如下:

[html]

?
1
2
<h1>分组式选项卡</h1>
<div class="content" id="content7"></div>


[Js]

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//分组式选项卡
var tabs7 = Ext.create('Ext.ux.GroupTabPanel', {
    activeGroup: 0,             //设置当前活动的分组
    items: [{
        expanded: false,
        mainItem: 1,            //设置主要的item,这个tab会在最上面,以文件夹方式展示出来。
        items: [{
            title: '项目1',
            html: "<b>第一组第一项正文。</b>"
        }, {
            title: '项目2',
            border: false,
            html: "<b>第一组第二项正文。</b>"
        }, {
            title: '项目3',
            border: false,
            html: "<b>第一组第三项正文。</b>"
        }]
    }, {
        expanded: true,
        items: [{
            title: '项目1',
            html: "<b>第二组第一项正文。</b>"
        }, {
            title: '项目2',
            html: "<b>第二组第二项正文。</b>"
        }]
    }]
});
Ext.create('Ext.Panel', {
    renderTo: "content7",
    width: 600,
    height: 250,
    collapsible: true,
    layout: 'fit',
    title: '分组tab演示',
    items: tabs7
});

 

效果:

转载于:https://www.cnblogs.com/webu/archive/2012/10/22/2733431.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/274560.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

一直刷不动算法题,怀疑人生?试试五毒掌法!

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。另外…

还在用开发者工具上传小程序? 快来试试 miniprogram-ci 提效摸鱼

1. 前言大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含包含jQuery、underscore、lo…

ListView几个比较特殊的属性

Android:stackFromBottom"true" 设置该属性之后你做好的列表就会显示在列表的最下面&#xff0c;值为true和false android:transcriptMode"alwaysScroll" 要用ListView或者其它显示大量Items的控件实时跟踪或者查看信息&#xff0c;并且希望最新的…

超级玛丽马里奥版下载_将超级马里奥赋予生命

超级玛丽马里奥版下载Have you ever seen a zoetrope? If today’s sophisticated computer animation is the latest evolution of the form, then the remarkable zoetrope is a crucial ancestor; the transitional form between the drawing and the animation.等皆你见过…

如何在繁重的工作中持续成长?

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。另外…

Mono for Android 对话框 倒计时

UI调度&#xff1a;public class Dispatcher : Handler { public override void HandleMessage(Message msg) { var ai msg.Obj as ActionItem; if (ai ! null) { try { …

熊kong作品资源链接_Kong雀技术:向世界展示您的设计作品

熊kong作品资源链接The door opened and I entered the bedroom of an apartment I was looking to rent. No furniture or items inside, it was almost empty except for a frame in the wall. It was a photo of a peacock. As I stared at it, I could not shake one clear…

漫谈前端工程化基建和架构设计 | 留言送书

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。本文留言抽奖送书&#xff0c;具体规则看文末。透过工程基建&#xff0c;架构有迹可循。前…

oracle中 rownum与rowid的理

一、 Oracle分页查询 我们先看学习一下oracle分页查询的语法示例&#xff0c;然后在具体学习用rownum的原理。 /*从第1条开始&#xff0c;每次选N个&#xff0c;从第1M个开始每次选N个*/ /**/ select t2.* from (select rid from (select r.rid, rownum linenum from (select r…

设计模式 日志系统设计_模式:我们设计系统的故事

设计模式 日志系统设计Design Patterns are some of the most over-used concepts in design today. And we all know what happens when you have some ideas all over the place. We start repeating them like parrots and applying them to everything, therefore distorti…

前端好还是后端好,看看7年前端和后端怎么说

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系列。另外…

提升UI技能的5个步骤

element ui 步骤重点 (Top highlight)What to do when you know how to use the software and know the basics of designing interfaces? There are a few simple things that you can do to take your skills to the next level, and you don’t need to invest in expensiv…

空降进阿里的 P10 都是什么人

周末见了几个朋友&#xff0c;吃饭时聊到他们前老板郭东白&#xff08;阿白&#xff09;&#xff0c;对了&#xff0c;我朋友在速卖通&#xff0c;他说阿白是 14 年来的阿里&#xff0c;直接就空降进了他们部门&#xff0c;当上首席架构师&#xff0c;后来又升到了 CTO&#xf…

linux下练习 c++ 关联式容器multimap特性

/* multimap特性 key可以重复 不支持下标访问 */ #include<iostream> #include<string> #include "print.h" #include<map> using namespace std; typedef pair<int,string> pairmp; typedef multimap<string,double> MS;int main() …

一致性设计,而不是一致性

一致性设计重点 (Top highlight)If we ask any design system advocate what are the main reasons to build and maintain a design system, chances are ‘Consistency’ will come up as first or second in their list, together with the ‘A single source of truth’ po…

如何在 React 应用中使用 Hooks、Redux 等管理状态

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此扫码加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系…

长语音识别体验_如何为语音体验写作

长语音识别体验重点 (Top highlight)“Voice User Interface (VUI) Designer” is an increasingly prominent job title in the tech world. A VUI designer typically writes the conversation and designs the flow between a VUI — an invisible interface that communica…

表连接

初学SQL表连接的时候&#xff0c;什么笛卡尔积&#xff0c;左连接&#xff0c;右连接看的头都大了 后来看了《SQL Server技术内幕2008&#xff1a;T-SQL查询》之后&#xff0c;豁然开朗。今天写数据库又用到了表连接&#xff0c;印象有点模糊了&#xff0c;赶紧找地方写下来先。…

分析了1011个程序员的裁员情况后得出的启示

大家好&#xff0c;我是若川。持续组织了近一年的源码共读活动&#xff0c;感兴趣的可以 点此扫码加我微信 ruochuan12 参与&#xff0c;每周大家一起学习200行左右的源码&#xff0c;共同进步。同时极力推荐订阅我写的《学习源码整体架构系列》 包含20余篇源码文章。历史面试系…

定义设计系统

System is “the whole creation, the universe,” from Late Latin systema “an arrangement, system,” from Greek systema “organized whole, a whole compounded of parts”.系统是晚期拉丁语系统的“整体创造物&#xff0c;宇宙”&#xff0c;是希腊语系统的“一种安排…