问题描述
我与木偶
工作,我有以下问题。
I'm working with Marionette
and I have the following problem.
我已经创建了两个不同的区域布局。在初始化
布局负荷在我的布局两个地区两种意见。说 ViewA
和 ViewB
。在 ViewA
事件被触发。本次活动由布局消耗的切换和其他两个视图注入。说 ViewC
和 ViewD
。
每当进行切换, ViewC
和 ViewD
不具有相同的风格(也是CSS)是我申请他们。特别是,jQuery Mobile的样式不适用。有什么建议?
I've created a layout with two different regions. On initialize
the layout loads two views in two regions of my layout. Say ViewA
and ViewB
. Within ViewA
an event is triggered. The event is consumed by the layout to switch and other two views are injected. Say ViewC
and ViewD
.Whenever the switching is performed, ViewC
and ViewD
do not have the same style (also the css) that I applied to them. In particular, jQuery Mobile styles are not applied. Any advice?
下面一些code,其中的意见突出的重要组成部分。
Here some code where comments highlight the important parts.
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);
}
修改
调用触发('创造')
似乎解决这个问题。为什么?这是正确的?
Calling trigger('create')
seems fix the problem. Why? Is this correct?
推荐答案
当你添加新的HTML页面(添加新的视图,一些其他观点交换看法,等等。),你必须让jQuery Mobile的了解这个。
When you add new html to page (add new rendered view, swap view for some other view, etc..), you have to let jQuery mobile know about this.
创建事件用于加强与jQuery Mobile的小部件原始的HTML。更多信息可以在这里找到:
寻找加强新的标记一节。
"create" event is used to enhance "raw" html with jQuery Mobile widgets. More info can be found here: http://jquerymobile.com/demos/1.0/docs/pages/page-scripting.htmlLook for "Enhancing new markup" section.
这篇关于从一个区域切换到另一个木偶,观点不正确呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!