[ExtJS5学习笔记]第二十九节 sencha ext js 5.1.0中动态更换皮肤主题

简介: 本文地址:http://blog.csdn.net/sushengmiyan/article/details/42016107 本文作者:sushengmiyan -------------------------------------------.

本文作者:sushengmiyan

------------------------------------------------------------------------------------------------------------------------------------

为方便起见,使用sencha cmd创建一个工程,使用app build命令build工程,使用web start命令启动服务。


好了,现在更改下main.js中的一点代码,增加如下内容到panel中:

,{
        xtype: 'combo',
        width: '100',
		labelWidth: '40',
		fieldLabel: 'Theme',
		displayField: 'name',
		valueField: 'value',
		//labelStyle: 'cursor:move;',
		//margin: '5 5 5 5',
		queryMode: 'local',
		store: Ext.create('Ext.data.Store', {
			fields: ['value', 'name'],
			data : [
				{ value: 'neptune', name: 'Neptune主题' },
				{ value: 'neptune-touch', name: 'Neptune Touch主题' },
				{ value: 'crisp', name: 'Crisp主题' },
				{ value: 'crisp-touch', name: 'Crisp Touch主题' },
				{ value: 'classic', name: 'Classic主题' },
				{ value: 'gray', name: 'Gray主题' }
			]
		}),
		//value: theme,
		listeners: {
			select: function(combo) {
				var  theme = combo.getValue();
				var	href = 'ext/packages/ext-theme-'+theme+'/build/resources/ext-theme-'+theme+'-all.css';
				var	link = Ext.fly('theme');
			 
				if(!link) {
					link = Ext.getHead().appendChild({
						 tag:'link',
						 id:'theme',
						 rel:'stylesheet',
						 href:''
					});
				};
				link.set({href:Ext.String.format(href, theme)});
			}
		}
    }

main.js代码应该如下所示:(完整内容)

/**
 * This class is the main view for the application. It is specified in app.js as the
 * "autoCreateViewport" property. That setting automatically applies the "viewport"
 * plugin to promote that instance of this class to the body element.
 *
 * TODO - Replace this content of this view to suite the needs of your application.
 */
Ext.define('oaSystem.view.main.Main', {
    extend: 'Ext.container.Container',
    requires: [
        'oaSystem.view.main.MainController',
        'oaSystem.view.main.MainModel'
    ],

    xtype: 'app-main',
    
    controller: 'main',
    viewModel: {
        type: 'main'
    },

    layout: {
        type: 'border'
    },

    items: [{
        xtype: 'panel',
        bind: {
            title: '{name}'
        },
        region: 'west',
        html: '<ul><li>This area is commonly used for navigation, for example, using a "tree" component.</li></ul>',
        width: 250,
        split: true,
        tbar: [{
            text: 'Button',
            handler: 'onClickButton'
        },{
        xtype: 'combo',
        width: '100',
		labelWidth: '40',
		fieldLabel: 'Theme',
		displayField: 'name',
		valueField: 'value',
		//labelStyle: 'cursor:move;',
		//margin: '5 5 5 5',
		queryMode: 'local',
		store: Ext.create('Ext.data.Store', {
			fields: ['value', 'name'],
			data : [
				{ value: 'neptune', name: 'Neptune主题' },
				{ value: 'neptune-touch', name: 'Neptune Touch主题' },
				{ value: 'crisp', name: 'Crisp主题' },
				{ value: 'crisp-touch', name: 'Crisp Touch主题' },
				{ value: 'classic', name: 'Classic主题' },
				{ value: 'gray', name: 'Gray主题' }
			]
		}),
		//value: theme,
		listeners: {
			select: function(combo) {
				var  theme = combo.getValue();
				var	href = 'ext/packages/ext-theme-'+theme+'/build/resources/ext-theme-'+theme+'-all.css';
				var	link = Ext.fly('theme');
			 
				if(!link) {
					link = Ext.getHead().appendChild({
						 tag:'link',
						 id:'theme',
						 rel:'stylesheet',
						 href:''
					});
				};
				link.set({href:Ext.String.format(href, theme)});
			}
		}
    }]
    },{
        region: 'center',
        xtype: 'tabpanel',
        items:[{
            title: 'Tab 1',
            html: '<h2>Content appropriate for the current navigation.</h2>'
        }]
    }]
});

纠结了很久的问题终于释怀了。之前看的都是使用swapstylesheet我一直么有成功过。偶尔看的了这篇文章,觉得不错,果真成功了。

http://extjs.eu/lightweight-theming/

推荐一下,这个网站,内容比较充实,界面也比较好看。就是有些插件需要花钱购买。

相关文章
|
10天前
|
Web App开发 前端开发 JavaScript
HTML/CSS/JS学习笔记 Day3(HTML--网页标签 下)
HTML/CSS/JS学习笔记 Day3(HTML--网页标签 下)
|
2月前
|
JavaScript
JS代码动态打印404页面源码
源码由HTML+CSS+JS组成,记事本打开源码文件可以进行内容文字之类的修改,双击html文件可以本地运行效果,也可以上传到服务器里面,重定向这个界面
25 0
JS代码动态打印404页面源码
|
2月前
|
JavaScript
js好用的动态分页插件
js好用的动态分页插件是一款简单的分页样式插件,支持样式类型,当前页,每页显示数量,按钮数量,总条数,上一页文字,下一页文字,输入框跳转等功能。
30 1
|
2月前
|
JavaScript 前端开发
vue 模拟随机变速的动态打字特效【支持多行文本】(含css实现闪烁光标,js动态改变setInterval定时器的时间间隔)
vue 模拟随机变速的动态打字特效【支持多行文本】(含css实现闪烁光标,js动态改变setInterval定时器的时间间隔)
51 1
|
3月前
|
前端开发 JavaScript
使用JavaScript动态更改元素的CSS属性
【6月更文挑战第29天】使用JavaScript动态更改元素的CSS属性
47 3
|
2月前
|
JavaScript Java 测试技术
基于springboot+vue.js+uniapp的云的学习笔记系统附带文章源码部署视频讲解等
基于springboot+vue.js+uniapp的云的学习笔记系统附带文章源码部署视频讲解等
31 0
|
4月前
|
数据采集 JavaScript 前端开发
使用Go和JavaScript爬取股吧动态信息的完整指南
本文介绍了如何使用Go和JavaScript构建网络爬虫,从股吧网站抓取实时股市信息。通过设置代理服务器以应对反爬策略,利用`got`库执行JavaScript提取动态数据,如用户讨论和市场分析。示例代码展示了爬虫的实现过程,包括浏览器实例创建、代理配置、JavaScript执行及数据打印。此方法有助于投资者及时获取市场资讯,为决策提供支持。
使用Go和JavaScript爬取股吧动态信息的完整指南
|
2月前
|
JavaScript 前端开发
前端 JS 经典:动态执行 JS
前端 JS 经典:动态执行 JS
23 0
|
3月前
|
JavaScript
js -- 函数总结篇,函数提升、动态参数、剩余参数、箭头函数、this指向......
js -- 函数总结篇,函数提升、动态参数、剩余参数、箭头函数、this指向......
|
4月前
|
JavaScript 前端开发
js中改变this指向、动态指定函数 this 值的方法
js中改变this指向、动态指定函数 this 值的方法