自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Sencha touch開發(fā)指南

移動開發(fā)
本文主要介紹如何使用Sencha Touch為手持設備進行應用開發(fā),主要是針對iPhone這樣的高端手機,我們會通過一個詳細的例子來介紹整個開發(fā)的流程。

Sencha touch 開發(fā)指南

Sencha Touch簡介

Sencha Touch是專門為移動設備開發(fā)應用的Javascrt框架。通過Sencha Touch你可以創(chuàng)建非常像native app的web app,用戶界面組件和數(shù)據(jù)管理全部基于HTML5和CSS3的web標準,全面兼容Android和Apple iOS。

如何使用Sencha Touch

1 下載Sencha Touch包,并按照以下結構創(chuàng)建項目列表

Sencha Touch包核心文件

上圖中加藍色背景的圖片為核心文件,必須載入。

2 創(chuàng)建HTML文件,引入以下CSS和Javascript文件

  1. <!DOCTYPE html> 
  2.   <html> 
  3.   <head> 
  4.       <meta charset="utf-8"> 
  5.       <title>Sencha Touch Test</title> 
  6.     
  7.      <!-- Sencha Touch CSS --> 
  8.     <link rel="stylesheet" href="../../resources/css/sencha-touch.css" type="text/css"> 
  9.    
  10.       <!-- Custom CSS --> 
  11.       <link rel="stylesheet" href="css/guide.css" type="text/css"> 
  12.     
  13.       <!-- Google Maps JS --> 
  14.       <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> 
  15.     
  16.       <!-- Sencha Touch JS --> 
  17.       <script type="text/javascript" src="../../sencha-touch-debug.js"></script> 
  18.     
  19.       <!-- Application JS --> 
  20.       <script type="text/javascript" src="src/index.js"></script> 
  21.    
  22. </head> 
  23.   <body></body> 
  24. </html> 

這樣我們的HTML結構就搭建完成了。#p#

3 使用Sencha Touch創(chuàng)建新的應用程序

我們在這里使用一個電視內(nèi)容查詢的應用來詳細介紹如何使用Sencha Touch來進行應用程序的開發(fā)。

我們首先使用Ext.setup方法來創(chuàng)建一個應用,你可以通過設置不同的參數(shù)來設置你的應用,具體的信息可以查閱API,查看Sencha Touch API Documentation。

代碼如下:

  1. Ext.setup({  
  2.  
  3. icon: 'icon.png',  
  4.  
  5.  tabletStartupScreen: 'tablet_startup.png',  
  6.  
  7.  phoneStartupScreen: 'phone_startup.png',  
  8.  
  9.  glossOnIcon: false,  
  10.  
  11.  onReady: function() {  
  12.  
  13.  }  
  14.  
  15. });  
  16.  

在上面的程序里面我們需要注意onReady方法,它會在整個DOM結構載入可用的情況下調(diào)用里面的內(nèi)容。

下面我們先在onReady下面創(chuàng)建一個TabPanel組件,并在其中添加我們需要的其他組件。

  1. var tabpanel = new Ext.TabPanel({  
  2.  
  3.  tabBar: { // an Ext.TabBar configuration  
  4.  
  5.  dock: 'bottom'//the tabbar position  
  6.  
  7.  layout: {  
  8.  
  9. pack: 'p' // the icon position  
  10.  
  11.  }  
  12.  
  13.  },  
  14.  
  15.  fullscreen: true//this component will take up the full width and height of the screen and automatically renders the component to the page  
  16.  
  17.  cardSwitchAnimation: {  
  18.  
  19.  type: 'pop',  
  20.  
  21.  cover: true 
  22.  
  23.  },  
  24.  
  25.  items: [{  
  26.  
  27.  title: 'Schedule',  
  28.  
  29.  iconCls: 'time',// the button icon  
  30.  
  31.  cls: 'card1'// an optional extra CSS class will be added to this component's element.  
  32.  
  33.  id: 'tab1',  
  34.  
  35.  dockedItems: [{  
  36.  
  37.  xtype: 'toolbar',  
  38.  
  39.  ui: 'light',  
  40.  
  41.  dock: 'top',  
  42.  
  43.  items: [  
  44.  
  45. tvTitle ,  
  46.  
  47.  { xtype: 'spacer' },  
  48.  
  49.  { text: 'Change...', ui: 'action', handler: function() {tvPicker.show();} },  
  50.  
  51.  ]  
  52.  
  53.  }, {  
  54.  
  55. xtype: 'panel',  
  56.  
  57. dock: 'bottom',  
  58.  
  59.  height: 48,  
  60.  
  61.  html: '' 
  62.  
  63.  }],  
  64.  
  65.  items: [  
  66.  
  67.  tvList  
  68.  
  69. ]  
  70.  
  71.  }, {  
  72.  
  73.  title: 'About',  
  74.  
  75.  html: '<table border="0" align="p" width="95%"><tr><td align="left"><br />' 
  76.                    +'<h1>Sport on TV</h1><br />Version 1.0 for iPhone<br />Using <a style="color:#000;text-decoration:none;" href="http://www.sencha.com/">Sencha Touch</a> framework.<br /><br /><br />' 
  77.                    +'<h1>Help</h1><br />Instantly discover what, when and where there is live sport on TV in the UK. (All times are GMT.)<br />To browse the schedule, tap <strong>Change...</strong> and select a sport and TV network. For additional information, tap the fixture.<br /><br /><br />' 
  78.                      +'<h1>Disclaimer</h1><br />Although every effort is made to ensure schedule information provided within the app is accurate, we can make no guarantee that it is always correct and can not accept responsibility for inaccurate information. Please double-check any fixtures that are important to you to avoid disappointment. Please also note that this app does not claim to stream video; it is a tool to display schedules of live sporting events on TV in the UK.<br /><br /><br />',  
  79.                     cls: 'card4',  
  80.                      styleHtmlContent: true,  
  81.                      iconCls: 'info',  
  82.                      id: 'tab2' 
  83.                  }]  
  84.              });  
  85.    
  86.            tvStore.load();  
  87.  

fullscreen這個參數(shù)是用來設置“首頁”的,就是把當前的組件設置成為用戶最先看到的組件。

Items是用來設置該組件下面的具體內(nèi)容。可以添加另外的組件到該組件下,使整個頁面可以靈活組合,實現(xiàn)各種功能。

在上面的代碼中我們在schedule這個tab下面又添加了tvList和tvTitle這兩個組件,tvList用來顯示后臺傳遞過來的數(shù)據(jù),tvTitle用來顯示當前的類別,我們會在下面做詳細的介紹。

最下面我們調(diào)用了tvStore.load(),這里是使用了Ext.data.Store組件,來讀取后臺的數(shù)據(jù)。在使用Store之前,我們還必須使用Ext.regModel來注冊一個model,供我們存放數(shù)據(jù)使用。代碼如下:

  1. Ext.regModel('tvGuide', {  
  2.  
  3. fields: ['tvSport''tvComp''tvChannel''tvGroup''tvDay''tvTime''tvFixture''tvIcon']  
  4.  
  5. });  
  6.  
  7.  var tvStore = new Ext.data.Store({  
  8.  
  9.  id: 'tvLocal',  
  10.  
  11.  model: 'tvGuide',  
  12.  
  13.  sorters: 'tvDay',  
  14.  
  15.  // autoLoad: true,  
  16.  
  17.  getGroupString: function(record) { return record.get('tvDay'); },  
  18.  
  19.  proxy: {  
  20.  
  21.  type: 'ajax',  
  22.  
  23.  url: 'http://localhost/sencha/test.txt',  
  24.  
  25.  reader: {  
  26.  
  27.  type: 'json',  
  28.  
  29.  root: 'fixtures' 
  30.  
  31.  }  
  32.  
  33.  },  
  34.  
  35.  filters: [  
  36.  
  37.  {  
  38.  
  39.  property: 'tvSport',  
  40.  
  41.  value: 'Football' 
  42.  
  43.  }  
  44.  
  45.  ]  
  46.  
  47.  });  
  48.  

這里使用了ajax去后臺讀取并返回json格式的數(shù)據(jù)。

text.txt是返回的json數(shù)據(jù),格式如下:

  1. {  
  2.  
  3.  "fixtures": [  
  4.  
  5. {"tvSport""Cricket""tvComp""The Ashes T3 D1""tvChannel""Sky Sports 1""tvGroup""Sky Sports""tvDay""Today""tvTime""02:00""tvFixture": "Australia  
  6. England", "tvIcon": "ss1.png"},  
  7.  
  8. {"tvSport""Golf""tvComp""SA Open""tvChannel""Sky Sports 3""tvGroup""Sky Sports""tvDay""Today""tvTime""08:30""tvFixture""Day 1""tvIcon""ss3.png"},  
  9.  
  10. {"tvSport""Cricket""tvComp""1st Test, Day 1""tvChannel""Sky Sports 1""tvGroup""Sky Sports""tvDay""Today""tvTime""10:00""tvFixture": "South Africa  
  11. India", "tvIcon": "ss1.png"},  
  12.  
  13. {"tvSport""Football""tvComp""Blue Square Premier""tvChannel""Premier Sport (MSK)""tvGroup""Other""tvDay""Today""tvTime""19:45""tvFixture": "Crawley Town  
  14. Mansfield Town", "tvIcon": "premsport.png"},  
  15.  
  16. {"tvSport""Football""tvComp""Victory Shield""tvChannel""Sky Sports 4""tvGroup""Sky Sports""tvDay""Today""tvTime""19:45""tvFixture": "England  
  17. Scotland", "tvIcon": "ss4.png"},  
  18.  
  19. {"tvSport""Fighting""tvComp""MMA""tvChannel""ESPN""tvGroup""ESPN""tvDay""Today""tvTime""22:30""tvFixture""UFC""tvIcon""espn.png"}  
  20.  
  21. ]}  
  22.  

數(shù)據(jù)有了,那我們怎么樣才能讓數(shù)據(jù)顯示出來呢?這里我們就需要使用tvList和tvTitle來顯示數(shù)據(jù)和數(shù)據(jù)的分類,代碼如下:

  1. var tvList = new Ext.List({  
  2.  
  3.  xtype: 'list',  
  4.  
  5.  store: tvStore,  
  6.  
  7. disableSelection: true,  
  8.  
  9.  scroll: 'vertical',  
  10.  
  11.  listeners: {  
  12.  
  13.  itemtap: function(list, index, item, e) {  
  14.  
  15.  var tvData = tvStore.getAt(index).data;  
  16.  
  17.  var tvMsg = tvData.tvFixture.replace('  
  18. ',' v ');  
  19.  
  20.  tvMsg += '  
  21. ' + tvData.tvComp;  
  22.  
  23.  tvMsg += '  
  24. ' + tvData.tvTime;  
  25.  
  26. Ext.Msg.alert(tvData.tvChannel,tvMsg,Ext.emptyFn);  
  27.  
  28.  }  
  29.  
  30. },  
  31.  
  32.                  itemTpl: '<table width="100%" style="background-image:url(chan/{tvIcon});background-position:right p;background-repeat:no-repeat;"><tr><td width="54" height="58" style="text-shadow:none;color:#666;font-size:16px;line-height:16px;">{tvTime}</td><td style="color:#222;text-shadow:none;">{tvFixture}</td></tr></table>',  
  33.  
  34. grouped: true,  
  35.  
  36.  height: 314  
  37.  
  38.  });  
  39.  
  40.  //tvTitle componet  
  41.  
  42. var tvTitle = new Ext.Panel({  
  43.  
  44. html: 'Football on all networks',  
  45.  
  46. xtype: 'panel',  
  47.  
  48. styleHtmlContent: true,  
  49.  
  50. styleHtmlCls: 'titlePanel',  
  51.  
  52.  cls: 'titlePanel' 
  53.  
  54.  });  
  55.  

通過上面的代碼我們知道tvList實際上是Ext.List的一個實例,通過設置store:tvStore,我們就把我們剛才通過Store取過來的數(shù)據(jù)放到了tvList上,并通過itemTpl展示到頁面上去的。而tvTitle其實也是一個Panel組件,它的作用就是顯示當前分類的名稱。

最后我們還要做一個篩選的功能,來找到我們喜歡的電視節(jié)目。我們看一下以前的代碼就會發(fā)現(xiàn)還有一個tvPicker.show();的方法,對了,這個就是用來調(diào)用選擇框的,用來完成篩選的功能,代碼如下:

  1. var tvPicker = new Ext.Picker({  
  2.  
  3.  height: 280,  
  4.  
  5.  doneButton: 'Search...',  
  6.  
  7.  listeners: {  
  8.  
  9.  "hide"function(tvPicker) {  
  10.  
  11. tvList.scroller.scrollTo( {x:0,y:0},false );  
  12.  
  13. var tvS = tvPicker.getValue().tvSport;  
  14.  
  15.  var tvC = tvPicker.getValue().tvChannel;  
  16.  
  17.  var tvD = tvS;  
  18.  
  19.  if(tvD=='American Football') tvD = 'NFL';  
  20.  
  21.  tvTitle.update(tvD + ' on ' + tvC);  
  22.  
  23.    
  24.  
  25.  if(tvC=='all networks') {  
  26.  
  27.  tvStore.clearFilter();  
  28.  
  29.  tvStore.filter('tvSport', tvS);  
  30.  
  31.  }  
  32.  
  33.  else {  
  34.  
  35.  tvStore.clearFilter();  
  36.  
  37.  tvStore.filter('tvSport', tvS);  
  38.  
  39.  tvStore.filter('tvGroup', tvC);  
  40.  
  41.  }  
  42.  
  43.    
  44.  
  45.  }  
  46.  
  47. },  
  48.  
  49.  slots: [  
  50.  
  51.  {  
  52.  
  53.  name: 'tvSport',  
  54.  
  55. title: 'Sport',  
  56.  
  57.  data: [  
  58.  
  59. { text: 'Football', value: 'Football' },  
  60.  
  61. { text: 'Rugby', value: 'Rugby' },  
  62.  
  63.  { text: 'Tennis', value: 'Tennis' },  
  64.  
  65.  { text: 'Cricket', value: 'Cricket' },  
  66.  
  67. { text: 'Golf', value: 'Golf' },  
  68.  
  69. { text: 'Fighting', value: 'Fighting' },  
  70.  
  71. { text: 'NFL', value: 'American Football' }  
  72.  
  73.  ]  
  74.  
  75.  }, {  
  76.  
  77. name: 'tvChannel',  
  78.  
  79. title: 'Channel',  
  80.  
  81.  data: [  
  82.  
  83.  { text: 'All networks', value: 'all networks' },  
  84.  
  85.  { text: 'Sky Sports', value: 'Sky Sports' },  
  86.  
  87.  { text: 'ESPN', value: 'ESPN' },  
  88.  
  89.  { text: 'Terrestrial', value: 'Terrestrial' }  
  90.  
  91. ]  
  92.  
  93. }  
  94.  
  95.  ]  
  96.  
  97.  });  
  98.  

這里是創(chuàng)建了Ext.Picker組件,具體的內(nèi)容就不多說了,大家看代碼就可以了。

最后別忘了發(fā)布應用的時候要把Sencha Touch的包換成壓縮過的版本,自己的代碼最好也壓縮一下,減少整個應用加載的時間。

最后看一下效果,記得要在safari或者chrome下看哦!

責任編輯:佚名 來源: 新浪ued
相關推薦

2011-09-02 15:18:49

Sencha Touc

2011-10-26 10:21:40

Sencha Touc組件

2012-01-10 13:21:33

Sencha Touc使用data包

2011-10-26 10:43:19

Sencha Touc

2011-10-26 10:32:05

Sencha Touc數(shù)據(jù)視圖

2011-10-18 09:49:40

新特征Sencha Touc

2011-09-05 11:23:26

EclipseSencha Touc框架

2010-11-22 10:31:17

Sencha touc

2011-07-26 09:41:50

Sencha Touc特性HTML 5

2011-07-25 15:55:21

Sencha ToucHtml 5

2011-09-02 16:42:51

Sencha ToucWeb應用

2011-09-05 11:27:17

Sencha Touc框架HTML5

2011-09-05 10:20:21

Sencha ToucAPP

2011-07-26 09:46:53

Sencha Touc

2012-02-28 14:48:41

2012-01-10 14:10:26

Sencha Touc

2011-07-26 09:58:24

2011-07-26 10:21:25

Sencha Touc

2011-07-26 10:44:15

Sencha Touc

2011-09-02 16:21:08

Sencha Touc自動生成工具
點贊
收藏

51CTO技術棧公眾號