Sencha Touch MVC 最佳实践 [英] Sencha Touch MVC Best Practices

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

问题描述

我正在尝试围绕 Sencha Touch 的 MVC 框架进行思考,但我找到了几种不同的方法.在 here 中,有一种在 SenchaCon 2010 上展示的构建 Sencha Touch 应用程序的方法.它增加了权重由 Sencha Touch 员工负责,但它已经有几个月的历史了.在其他关于 Sencha Touch MVC 的最新帖子中,他们有教程(例如 这里,以及 Manning 的 MEAP Sencha In Action by Jay Garcia),它似乎依赖于视图中的 Ext.Dispatch 来调用特定的控制器方法,将额外的元素传递给控制器​​,这使得视图能够感知控制器.

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.

我的问题是,哪种被认为是构建 Sench Touch MVC 应用程序的最佳实践?

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.

我使用 UI 管理器进行全局 UI 更改,例如隐藏/显示主工具栏或显示后退按钮.

I use an UI manager for global UI changes like hiding / showing a main toolbar or displaying a back button.

这篇关于Sencha Touch MVC 最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆