Sencha Touch MVC最佳做法 [英] Sencha Touch MVC Best Practices
问题描述
我的问题是,这被认为是构建Sench Touch MVC应用程序的最佳实践?
我建议您的控制器视图感知。当一个控制器收到一个调度事件时,你应该有一些类似于以下的东西:
this.controllerViewOne = this.controllerViewOne
|| this.render({
xtype:'panel',
listeners:{
onMajorUIAction:function(params){
Ext.Dispatch({
controller:'ProperController ',
action:'ProperAction',
historyUrl:'ProperHistoryUrl',
params:params
});
}
}
});
这样可以让每个控制器视图的所有主一个空间这也意味着重用其他控制器的视图变得更加容易。
您的视图应该都有听众,可以帮助抽象出各个组件及其事件/侦听器的复杂性。 p>
我使用UI管理器进行全局UI更改,如隐藏/显示主工具栏或显示后退按钮。
I'm trying to wrap my mind around the MVC framework of Sencha Touch, but I'm finding a couple of different approaches. In one, found here, there is an approach to structuring Sencha Touch apps presented at SenchaCon 2010. It has the added weight of being by a Sencha Touch employee, but it is several months old. In other, more recent posts on Sencha Touch MVC, they have tutorials (such as here, as well as Manning's MEAP Sencha In Action by Jay Garcia) that seem to rely on Ext.Dispatch in the views to call specific controller methods, passing additional elements to the controller, which makes the views controller-aware.
My question is, which is considered the best practice to structure a Sench Touch MVC app?
I suggest making your controllers view-aware. When a controller receives a dispatch event you should have something similar to the following:
this.controllerViewOne = this.controllerViewOne
|| this.render({
xtype: 'panel',
listeners: {
onMajorUIAction : function(params){
Ext.Dispatch({
controller : 'ProperController',
action : 'ProperAction',
historyUrl : 'ProperHistoryUrl',
params : params
});
}
}
});
This has the added benefit of having all of the "Main" listeners for each of the controllers views in one space. It also means reusing the views for other controllers becomes easier.
Your views should all have listeners that help abstract the complexities of the individual components and their events / listeners.
I use an UI manager for global UI changes like hiding / showing a main toolbar or displaying a back button.
这篇关于Sencha Touch MVC最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!