我正在与Marionette
我有以下问题。
我创建了一个包含两个不同区域的布局。在initialize
该布局在布局的两个区域中加载两个视图。说ViewA
and ViewB
。之内ViewA
一个事件被触发。该事件由布局消耗以进行切换,并注入其他两个视图。说ViewC
and ViewD
。
每当进行切换时,ViewC
and ViewD
没有我应用到它们的相同样式(还有CSS)。特别是,不应用 jQuery Mobile 样式。有什么建议吗?
这里有一些代码,其中注释突出显示了重要部分。
onConfirm : function() {
this.leftView = new ViewC();
this.rightView = new ViewD();
this.leftRegion.show(this.leftView);
this.rightRegion.show(this.rightView);
// FIX calling trigger('create') seems fix the problem. Why? Is this correct?
this.$el.trigger('create');
},
initialize : function() {
// listen for event triggered from ViewA
// e.g. GloabalAggregator.vent.trigger("ga:confirm");
// where "ga:confirm" is a simple string
GloabalAggregator.vent.on("ga:confirm" , this.onConfirm, this);
this.leftView = new ViewA(), // creating here a new ViewC the style is applied correctly
this.rightView = new ViewB(); // creating here a new ViewD the style is applied correctly
},
onRender : function () {
this.leftRegion.show(this.leftView);
this.rightRegion.show(this.rightView);
}
EDIT
Calling trigger('create')
似乎解决了问题。为什么?它是否正确?
当您向页面添加新的 html(添加新的渲染视图、将视图交换为其他视图等)时,您必须让 jQuery mobile 了解这一点。
“create”事件用于通过 jQuery Mobile 小部件增强“原始”html。更多信息可以在这里找到:http://jquerymobile.com/demos/1.0/docs/pages/page-scripting.html http://jquerymobile.com/demos/1.0/docs/pages/page-scripting.html查找“增强新标记”部分。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)