浅谈Sencha Touch初体验

移动开发
前不久基于JavaScript编写的Ajax框架ExtJS,将现有的ExtJS整合JQTouch、Raphaël库,推出适用于最前沿Touch Web的Sencha Touch框架,该框架是世界上第一个基于HTML5的Mobile App框架。

Sencha Touch可以让你的Web App看起来像Native App。美丽的用户界面组件和丰富的数据管理,全部基于最新的HTML5和CSS 3的 WEB标准,全面兼容AndroidApple iOS设备。

一、什么是Sencha Touch

Sencha Touch是一个应用手持移动设备的前端js框架,与extjs是同一个门派的,它继承了extjs的优点和缺点。功能很强大,效果很炫丽,效率不高。

二、例子来了

效果图:Sencha touch官方一个list的example

浅谈Sencha Touch初体验

PS:模拟器访问本地server的地址是10.0.2.2:8080,而不是127.0.0.1:8080

1、导入touch的相关js,css以及资源文件

2、index.html

  1. <!DOCTYPEhtml> 
  2. <html> 
  3. <head> 
  4. <metahttp-equivmetahttp-equiv="Content-Type"content="text/html; charset=utf-8"> 
  5. <metanamemetaname="viewport"content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=0;" /> 
  6. 6:<title>Sencha Touch List Example</title> 
  7. <!-- import touch css and js --> 
  8. <linkrellinkrel="stylesheet"href="touch/resources/css/sencha-touch.css"type="text/css"> 
  9. <scripttypescripttype="text/javascript"src="touch/sencha-touch-debug.js">
  10. </script><scripttypescripttype="text/javascript"src="src/index.js"></script> 10:
  11. </head> 
  12. <body></body>   
  13. </html> 

3、index.js

  1. /**  
  2.      * 前言:  
  3.      * 此例子来自sencha touch的官方example  
  4.      * 注释用语如有不当请见谅。  
  5.      */  
  6. //相信这是每个页面都是一样的  
  7.     Ext.setup({  
  8.         tabletStartupScreen: 'tablet_startup.png',  
  9.         phoneStartupScreen: 'phone_startup.png',  
  10.    icon: 'icon.png',  
  11. glossOnIcon: false,  
  12. onReady : function() {  
  13.            //注册一个名为“Contact”的模型,显示的字段为firstName和lastName  
  14.            Ext.regModel('Contact', {  
  15.                fields: ['firstName', 'lastName']  
  16.            });  
  17.            //定义一个对象,有点类似Android里面的BaseAdapter  
  18.            var groupingBase = {  
  19.                itemTpl: '<div class="contact2"><strong>{firstName}</strong> {lastName}</div>',  
  20.                selModel: {//选择模型,单选;应该还有多选  
  21.                    mode: 'SINGLE',  
  22.                    allowDeselect: true  
  23.                },  
  24.                grouped: true,//分组  
  25.                indexBar: true, //索引栏  
  26.                  
  27.                //定义点击事件  
  28.                onItemDisclosure: {  
  29.                    scope: 'test',  
  30.                    //事件处理  
  31.                    handler: function(record, btn, index) {  
  32.                        alert('Disclose more info for ' + record.get('firstName'));  
  33.                    }  
  34.                },  
  35.                //数据仓库  
  36.                store: new Ext.data.Store({  
  37.                    model: 'Contact',//与上面注册的模型对应  
  38.                    sorters: 'firstName',//排序字段  
  39.                      
  40.                    //分组title显示的数据源,为firstName的首字母  
  41.                    getGroupString : function(record) {  
  42.                        return record.get('firstName')[0];  
  43.                    },  
  44.                    //就是数据了  
  45.                    data: [  
  46.                        {firstName: 'Aaron', lastName: 'Conran'},  
  47.                        {firstName: 'Ape', lastName: 'Evilias'},  
  48.                        {firstName: 'Dave', lastName: 'Kaneda'},  
  49.                        {firstName: 'Michael', lastName: 'Mullany'},  
  50.                        {firstName: 'Abraham', lastName: 'Elias'},  
  51.                        {firstName: 'Jay', lastName: 'Robinson'},  
  52.                        {firstName: 'Tommy', lastName: 'Maintz'},  
  53.                        {firstName: 'Ed', lastName: 'Spencer'},  
  54.                        {firstName: 'Jamie', lastName: 'Avins'},  
  55.                        {firstName: 'Ed', lastName: 'Spencer'},  
  56.                        {firstName: 'Jamie', lastName: 'Avins'},  
  57.                        {firstName: 'Aaron', lastName: 'Conran'},  
  58.                        {firstName: 'Dave', lastName: 'Kaneda'},  
  59.                        {firstName: 'Ape', lastName: 'Evilias'},  
  60.                        {firstName: 'Dave', lastName: 'Kaneda'},  
  61.                       {firstName: 'Michael', lastName: 'Mullany'},  
  62.                        {firstName: 'Abraham', lastName: 'Elias'},  
  63.                        {firstName: 'Jay', lastName: 'Robinson'},  
  64.                        {firstName: 'Tommy', lastName: 'Maintz'},  
  65.                        {firstName: 'Ed', lastName: 'Spencer'},  
  66.                        {firstName: 'Jamie', lastName: 'Avins'},  
  67.                        {firstName: 'Aaron', lastName: 'Conran'},  
  68.                        {firstName: 'Dave', lastName: 'Kaneda'},  
  69.                        {firstName: 'Michael', lastName: 'Mullany'},  
  70.                        {firstName: 'Abraham', lastName: 'Elias'},  
  71.                        {firstName: 'Jay', lastName: 'Robinson'},  
  72.                        {firstName: 'Tommy', lastName: 'Maintz'},  
  73.                        {firstName: 'Ed', lastName: 'Spencer'},  
  74.                        {firstName: 'Jamie', lastName: 'Avins'},  
  75.                        {firstName: 'Aaron', lastName: 'Conran'},  
  76.                        {firstName: 'Dave', lastName: 'Kaneda'},  
  77.                       {firstName: 'Michael', lastName: 'Mullany'},  
  78.                        {firstName: 'Abraham', lastName: 'Elias'},  
  79.                        {firstName: 'Jay', lastName: 'Robinson'},  
  80.                        {firstName: 'Michael', lastName: 'Mullany'},  
  81.                        {firstName: 'Abraham', lastName: 'Elias'},  
  82.                       {firstName: 'Jay', lastName: 'Robinson'},  
  83.                        {firstName: 'Zed', lastName: 'Zacharias'}  
  84.                    ]  
  85.                })  
  86.            };  
  87.            /**  
  88.             * 应该是判断设备类型把  
  89.             * Phone和其他类型有所不同,主要就是屏幕大小了  
  90.             */  
  91.            if (!Ext.is.Phone) {  
  92.                new Ext.List(Ext.apply(groupingBase, {  
  93.                    floating: true,  
  94.                   width: 350,  
  95.                    height: 370,  
  96.                    centered: true,  
  97.                    modal: true,  
  98.                   hideOnMaskTap: false  
  99.               })).show();  
  100.           }  
  101.           else {  
  102.               new Ext.List(Ext.apply(groupingBase, {  
  103.                   fullscreen: true  //全屏  
  104.               }));  
  105.          }  
  106.       }  
  107.   }); 

4、部署到服务器访问就行了。

END!!!

小结:浅谈Sencha Touch初体验的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2010-11-22 10:31:17

Sencha touc

2011-09-02 16:21:08

Sencha Touc自动生成工具

2011-09-05 13:53:08

Sencha Touc列表

2011-09-05 10:27:02

Sencha Touc手机应用Android

2011-09-05 13:48:36

Sencha Touc图标

2011-09-02 15:18:49

Sencha Touc

2011-07-26 09:41:50

Sencha Touc特性HTML 5

2011-07-25 15:55:21

Sencha ToucHtml 5

2011-07-26 09:46:53

Sencha Touc

2011-07-25 16:21:22

Sencha touc

2011-07-25 16:41:16

Sencha Touc

2011-11-28 13:42:55

Sencha Touc组件选择器

2011-09-05 10:39:03

Sencha Touc离线存储数据库

2011-09-05 14:09:06

Sencha Touc函数

2011-09-05 12:49:59

Sencha Touc事件

2011-09-05 11:23:26

EclipseSencha Touc框架

2011-09-02 15:12:29

PhoneGapSencha Touc

2012-03-08 22:31:28

Sencha Touc

2011-09-02 16:42:51

Sencha ToucWeb应用

2011-10-26 10:21:40

Sencha Touc组件
点赞
收藏

51CTO技术栈公众号