jQuery Mobile教程:組件如何自動初始化

來源:互聯網
上載者:User

文章簡介:本文我們來深度認識一下jQuery Mobile的內部設計原理中組件如何自動初始化。

本文我們來深度認識一下jQuery Mobile的內部設計原理中組件如何自動初始化
(注釋:下面樣本中的程式碼片段均來自1.1.0版本)
很多看過源碼的同學或者使用過jquery mobile的同學們,大家有沒有一個很大很大的問題:
------- jquery mobile提供了幾個組件,他們如何自動初始化的?
!!重點說明:下面類似的自動初始化的流程多是在pagecreate觸發後調用,有關pagecreate相關的說明可以查看我前面的相關介紹

我們挑選其中一個組件:listview

先看一張流程圖:

源碼樣本:

//#5193 綁定在pagecreate裡面 $(document).bind("pagecreate create",function(e){ //調用enhanceWithin,傳遞了一個參數:target(dom對象) $.mobile.listview.prototype.enhanceWithin(e.target); }); 
1、$.mobile.listview.prototype.enhanceWithin
//#1203 enhanceWith:function(target,useKeepNative){ //調用this.enhance //這邊注意:會讀取options.initSelector來過濾選擇 this.enhance($(this.options.initSelector,$(target)),useKeepNative); }, 
2、enhance
//1207 enhance:function(targets,useKeepNative){ var $widgetElements = $(targets);  //......  $widgetElements = $.mobile.enhanceable($widgetElements);  //注意: //this.widgetName:listview ===> 在#979行裝載進來的widgetName:name //轉換為調用外掛程式式 //$(selector)["listview"](); $widgetElements[this.widgetName](); }, 


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.