本文介绍了Sencha Touch MVC最佳做法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图围绕着Sencha Touch的MVC框架,但是我发现了几种不同的方法。在其中,发现,有一种方法来构建SenchaCon 2010上提供的Sencha Touch应用程序。它具有增加的重量由Sencha Touch的员工担任,但是还有几个月的时间。另外,Sencha Touch MVC最近发表的文章还有教程(例如,以及Manning公司的杰作加西亚的Sencha In Action)似乎依赖于Ext.Dispatch在视图中调用特定的控制器方法,将附加元素传递给控制器​​,这使得视图控制器感知



我的问题是,这被认为是构建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最佳做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 04:57