[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/

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

相关文章
|
3月前
|
JavaScript 前端开发
实现一个JavaScript动态日期功能
实现一个JavaScript动态日期功能
|
5月前
|
JavaScript 小程序
小程序JS动态修改样式vv
小程序JS动态修改样式
140 0
|
1月前
|
JavaScript
JS动态转盘可自由设置个数与概率
JS动态转盘可自由设置个数与概率
|
1月前
|
JavaScript
JS动态参数arguments与剩余参数
JS动态参数arguments与剩余参数
|
2月前
|
前端开发 JavaScript API
JavaScript学习笔记(一)promise与async
JavaScript学习笔记(一)promise与async
|
2月前
|
JavaScript 前端开发
js制作动态表单
js制作动态表单
18 0
|
6月前
|
JavaScript 前端开发
js和css3实现动态魔方的效果
js和css3实现动态魔方的效果
49 0
|
6月前
|
存储 JavaScript 前端开发
手撕前端面试题【javascript~ 列表动态渲染、无重复数组、数组排序、新数组、创建数组、深浅拷贝、内存泄露等】
html页面的骨架,相当于人的骨头,只有骨头是不是看着有点瘆人,只有HTML也是如此。 css,相当于把骨架修饰起来,相当于人的皮肉。
39 0
|
2月前
|
JavaScript 前端开发 Java
MooTools、Backbone、Sammy、Cappuccino、Knockout、JavaScript MVC、Google Web Toolkit、Google Closure、Ember、Batman 以及 Ext JS。
MooTools、Backbone、Sammy、Cappuccino、Knockout、JavaScript MVC、Google Web Toolkit、Google Closure、Ember、Batman 和 Ext JS 都是 JavaScript 框架,用于开发 Web 应用程序。它们分别提供了不同的功能和特性,以帮助开发者更高效地构建和维护 Web 应用程序。
17 2
|
2月前
|
前端开发 JavaScript UED
动态伸缩搜索框:HTML, CSS, JavaScript的完美结合
动态伸缩搜索框:HTML, CSS, JavaScript的完美结合
79 1