编辑:
Rixo 完全正确——你不能为已经渲染的组件动态更改 Ext 主题。
解决方法是在应用程序启动时加载主题。为此,您需要将所选主题名称存储在可以在页面刷新后保留的位置。ExtJS 示例页面使用查询参数,但我选择了 cookie。在我的里面我index.jsp
放了以下内容:
<script type="text/javascript">
var consoleLogEnabled = true;
var contextPath = "${pageContext.request.contextPath}";
var theme = 'default';
if (document.cookie) {
index = document.cookie.indexOf('theme');
if (index !== -1) {
f = (document.cookie.indexOf("=", index) + 1);
t = document.cookie.indexOf(";", index);
if (t === -1) {
t = document.cookie.length;
}
theme = (document.cookie.substring(f, t));
}
}
if ((theme === 'default') || (theme !== 'gray' && theme !== 'access' && theme !== 'neptune'))
document.write('<link rel="stylesheet" type="text/css" href="js/ext-js/resources/css/ext-all-debug.css" />');
else
document.write('<link rel="stylesheet" type="text/css" href="js/ext-js/resources/css/ext-all-' + theme + '-debug.css" />');
document.write('<script type="text/javascript" src="js/ext-js/ext-all-debug-w-comments.js"></scr'+'ipt>');
if (theme === 'neptune')
document.write('<script type="text/javascript" src="js/ext-js/ext-theme-neptune.js"></scr'+'ipt>');
</script>
<link rel="stylesheet" type="text/css" href="resources/css/myapp-style.css" />
<script type="text/javascript" src="js/myapp/myapp.js"></script>
现在,当我想更改主题时,只需在控制器中执行以下操作:
changeTheme : function(theme) {
if (theme !== Ext.util.Cookies.get('theme')) {
Ext.util.Cookies.set('theme', theme);
location = location; // Refresh of page cannot be avoided as its an Ext-JS limitation
}
中提琴 - 它只是工作。