欢迎来到天天文库
浏览记录
ID:37712836
大小:34.02 KB
页数:12页
时间:2019-05-29
《Sencha Touch 2 控制器指南》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、前言:控制器[Controller]在SenchaTouchMVC中起到的是纽带作用,它控制视图[View]的展示逻辑,又负责以数据模型[Model]为基础的数据[Data]处理逻辑(包括数据的加载、展示、更新、增删等等)。控制器就像胶水,有了它才能够把一个SenchaTouch(后面一律简写做ST)应用程序[Application]的各项元素黏合在一起,使之协调工作并完成预期的任务。文章英文原址是:http://docs.sencha.com/touch/2-0/#!/guide/controllers原文标题是Controllers,直
2、译就是控制器,不过在官方文档中也称之为ControllersGuide,我觉得用这个标题更为恰切一些。SenchaTouch交流QQ群213119459ControllersGuide控制器学习指南Controllersareresponsibleforrespondingtoeventsthatoccurwithinyourapp.IfyourappcontainsaLogout button thatyourusercantapon,aControllerwouldlistentotheButton'stapeventandtaketh
3、eappropriateaction.ItallowstheViewclassestohandlethedisplayofdataandtheModelclassestohandletheloadingandsavingofdata-theControlleristhegluethatbindsthemtogether.控制器用来响应发生在应用程序中的事件,如果你的应用程序包含一个让用户点击的登出按钮,那么就应该有一个控制器来侦听该按钮的点击事件然后作出恰当的反应。控制器就像胶水,它控制视图类展示数据,并通过数据模型类来加载和保存数据,于是
4、两者就这样被黏合在一起。Relationto Ext.app.Application控制器与Ext.app.Application的关系Controllersexistwithinthecontextofan Application.AnApplicationusuallyconsistsofanumberofControllers,eachofwhichhandleaspecificpartoftheapp.Forexample,anApplicationthathandlestheordersforanonlineshoppingsit
5、emighthavecontrollersforOrders,CustomersandProducts.控制器存在于应用程序的上下文环境中,一个应用程序通常有若干的控制器组成,每一个控制器分别负责实现应用程序中某一个特定的功能部分,例如一个处理在线商城销售订单的应用程序就可能会包含订单、客户、产品等控制器。AlloftheControllersthatanApplicationusesarespecifiedintheApplication's Ext.app.Application.controllers config.TheApplic
6、ationautomaticallyinstantiateseachControllerandkeepsreferencestoeach,soitisunusualtoneedtoinstantiateControllersdirectly.ByconventioneachControllerisnamedafterthething(usuallytheModel)thatitdealswithprimarily,usuallyintheplural-forexampleifyourappiscalled'MyApp'andyouhavea
7、ControllerthatmanagesProducts,conventionistocreateaMyApp.controller.Productsclassinthefileapp/controller/Products.js.所有应用程序用到的控制器都在Ext.app.Application.controllers 中进行声明,应用程序会自动实例化每一个控制器并保持对它们的引用,因此我们一般无需自己去直接实例化控制器。按照惯例,每一个控制器的命名应该对应他要处理的事物(通常是数据模型),而且常常是复数形式。例如你的应用程序叫做“My
8、App”,你需要一个用来管理产品的控制器,按照常规就应该在app/controller/Products.js文件中创建一个MyApp.controller.Products的类
此文档下载收益归作者所有