Ember.js - currentViewBinding并在每个视图转换时停止重新渲染 [英] Ember.js - currentViewBinding and stop re-rendering on every view transition
问题描述
index:Ember.State.create({
enter:function(manager){
App.get('appController')。set('feedView',Ember.View.create {
templateName:'dashboard_feed',
contentBinding:'App.feedController.content',
控制器:App.get('App.feedController')
});
}
})
在这个时刻,渲染这些视图相当慢有没有办法可以保持内存中的视图,避免每次进入状态时重新渲染?
我实际上为StackOverflow的另一个问题提供了一个解决方案,但这里也是非常重要的。 避免重新重新激活视图时,从头开始闪存flash对象
这是jsFiddle: http://jsfiddle.net/EE3B8/1
我用一个标志来扩展ContainerView,以阻止它破坏当前的视图被破坏。你会希望将视图实例隐藏在不会被销毁的地方。
应用程序.ImmortalContainerView = Ember.ContainerView.extend({
destroyCurrentView:true,
willDestroy:function(){
if(!this.destroyCurrentView){this._currentViewWillChange(); }
this._super();
}
});
App.immortalView = Ember.View.create({
template:Ember.Handlebars.compile(
'I WILL LIVE FOREVER!'
)
});
I have a statemachine and I am using the new currentViewBinding to swap out parts of an overall containerView whenever a new state is entered using currentViewBinding:
index: Ember.State.create({
enter: function(manager) {
App.get('appController').set('feedView', Ember.View.create({
templateName: 'dashboard_feed',
contentBinding: 'App.feedController.content',
controller: App.get('App.feedController')
}));
}
})
At this moment in time, the rendering of these view is quite slow. Is there a way I could keep the view in memory and avoid the re-rendering every time I enter the state?
I actually provided a solution to this for another question on StackOverflow, but it's super relevant here too. Avoiding re-rendering of a flash object from scratch when view is reactivated
Here's the jsFiddle: http://jsfiddle.net/EE3B8/1
I extend ContainerView with a flag to stop it from destroying the currentView upon it's destruction. You'll want to stash the view instance somewhere that it won't be destroyed.
App.ImmortalContainerView = Ember.ContainerView.extend({
destroyCurrentView: true,
willDestroy: function() {
if (!this.destroyCurrentView) { this._currentViewWillChange(); }
this._super();
}
});
App.immortalView = Ember.View.create({
template: Ember.Handlebars.compile(
'I WILL LIVE FOREVER!'
)
});
这篇关于Ember.js - currentViewBinding并在每个视图转换时停止重新渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!