Submit Search
Upload
Backbone js and requirejs
•
Download as ODP, PDF
•
2 likes
•
1,243 views
Chi-wen Sun
Follow
Backbonejs and RequireJS
Read less
Read more
Business
Technology
Report
Share
Report
Share
1 of 14
Download now
Recommended
Template mb-kao
Template mb-kao
xwcoder
Angular2 Form
Angular2 Form
Rainmaker Ho
Kissy design
Kissy design
yiming he
Web设计 4 锋利的j_query(进入企业级应用阶段)
Web设计 4 锋利的j_query(进入企业级应用阶段)
ziggear
J query
J query
waitcat
第十期 阿甘Javascript开发思想(入门篇)
第十期 阿甘Javascript开发思想(入门篇)
9scss
Kissy简介
Kissy简介
jay li
KISSY for starter
KISSY for starter
yiming he
Recommended
Template mb-kao
Template mb-kao
xwcoder
Angular2 Form
Angular2 Form
Rainmaker Ho
Kissy design
Kissy design
yiming he
Web设计 4 锋利的j_query(进入企业级应用阶段)
Web设计 4 锋利的j_query(进入企业级应用阶段)
ziggear
J query
J query
waitcat
第十期 阿甘Javascript开发思想(入门篇)
第十期 阿甘Javascript开发思想(入门篇)
9scss
Kissy简介
Kissy简介
jay li
KISSY for starter
KISSY for starter
yiming he
Phalcon框架入门
Phalcon框架入门
xiaopei li 李小培
JQuery 学习
JQuery 学习
cssrain
16 CoreData
16 CoreData
Tom Fan
Mvc
Mvc
tbmallf2e
02 Objective-C
02 Objective-C
Tom Fan
Ch05 Servlet 進階 API、過濾器與傾聽器
Ch05 Servlet 進階 API、過濾器與傾聽器
Justin Lin
15 Subclassing UITableViewCell
15 Subclassing UITableViewCell
Tom Fan
Sina App Quick Guide 1
Sina App Quick Guide 1
guestf4aed35
I os 08
I os 08
信嘉 陳
Node way
Node way
Ethan Zhang
Backbone.js and MVW 101
Backbone.js and MVW 101
Jollen Chen
Node getting-started
Node getting-started
lylijincheng
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
Ming-Sian Lin
05 MapKit and Text Input
05 MapKit and Text Input
Tom Fan
Underscore
Underscore
cazhfe
Ch09 整合資料庫
Ch09 整合資料庫
Justin Lin
10. 資料永續與交換
10. 資料永續與交換
Justin Lin
jQuery 選取器解析
jQuery 選取器解析
Kingsley Zheng
14 Saving Loading and Application States
14 Saving Loading and Application States
Tom Fan
CH09:Collection與Map
CH09:Collection與Map
Justin Lin
2012 review
2012 review
106174CL
Dulcelandia Febrero 2010
Dulcelandia Febrero 2010
ademirac
More Related Content
What's hot
Phalcon框架入门
Phalcon框架入门
xiaopei li 李小培
JQuery 学习
JQuery 学习
cssrain
16 CoreData
16 CoreData
Tom Fan
Mvc
Mvc
tbmallf2e
02 Objective-C
02 Objective-C
Tom Fan
Ch05 Servlet 進階 API、過濾器與傾聽器
Ch05 Servlet 進階 API、過濾器與傾聽器
Justin Lin
15 Subclassing UITableViewCell
15 Subclassing UITableViewCell
Tom Fan
Sina App Quick Guide 1
Sina App Quick Guide 1
guestf4aed35
I os 08
I os 08
信嘉 陳
Node way
Node way
Ethan Zhang
Backbone.js and MVW 101
Backbone.js and MVW 101
Jollen Chen
Node getting-started
Node getting-started
lylijincheng
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
Ming-Sian Lin
05 MapKit and Text Input
05 MapKit and Text Input
Tom Fan
Underscore
Underscore
cazhfe
Ch09 整合資料庫
Ch09 整合資料庫
Justin Lin
10. 資料永續與交換
10. 資料永續與交換
Justin Lin
jQuery 選取器解析
jQuery 選取器解析
Kingsley Zheng
14 Saving Loading and Application States
14 Saving Loading and Application States
Tom Fan
CH09:Collection與Map
CH09:Collection與Map
Justin Lin
What's hot
(20)
Phalcon框架入门
Phalcon框架入门
JQuery 学习
JQuery 学习
16 CoreData
16 CoreData
Mvc
Mvc
02 Objective-C
02 Objective-C
Ch05 Servlet 進階 API、過濾器與傾聽器
Ch05 Servlet 進階 API、過濾器與傾聽器
15 Subclassing UITableViewCell
15 Subclassing UITableViewCell
Sina App Quick Guide 1
Sina App Quick Guide 1
I os 08
I os 08
Node way
Node way
Backbone.js and MVW 101
Backbone.js and MVW 101
Node getting-started
Node getting-started
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
iOS App 開發 -- Storybard 基礎練習、APP 上架、IAP
05 MapKit and Text Input
05 MapKit and Text Input
Underscore
Underscore
Ch09 整合資料庫
Ch09 整合資料庫
10. 資料永續與交換
10. 資料永續與交換
jQuery 選取器解析
jQuery 選取器解析
14 Saving Loading and Application States
14 Saving Loading and Application States
CH09:Collection與Map
CH09:Collection與Map
Viewers also liked
2012 review
2012 review
106174CL
Dulcelandia Febrero 2010
Dulcelandia Febrero 2010
ademirac
UI Engineering Introduction
UI Engineering Introduction
Hsuan Fu Lien
ხათუნა
ხათუნა
xatunakaxidze
前端框架Redux實作
前端框架Redux實作
Chi-wen Sun
前端框架發展
前端框架發展
Chi-wen Sun
estratto_maestri_nella_nuova_energia
estratto_maestri_nella_nuova_energia
Laviadelcuore
Nodejs api server_implement
Nodejs api server_implement
Chi-wen Sun
Overview of Backbone
Overview of Backbone
John Ashmead
Modern web develop
Modern web develop
Chi-wen Sun
Purple people eater
Purple people eater
nanwood
前端MVC之backbone
前端MVC之backbone
Jerry Xie
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
Barry Feldman
Viewers also liked
(13)
2012 review
2012 review
Dulcelandia Febrero 2010
Dulcelandia Febrero 2010
UI Engineering Introduction
UI Engineering Introduction
ხათუნა
ხათუნა
前端框架Redux實作
前端框架Redux實作
前端框架發展
前端框架發展
estratto_maestri_nella_nuova_energia
estratto_maestri_nella_nuova_energia
Nodejs api server_implement
Nodejs api server_implement
Overview of Backbone
Overview of Backbone
Modern web develop
Modern web develop
Purple people eater
Purple people eater
前端MVC之backbone
前端MVC之backbone
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
Similar to Backbone js and requirejs
Django development
Django development
loveyudu
Introduction to CodeIgniter
Introduction to CodeIgniter
Chun-Kai Wang
旺铺前端设计和实现
旺铺前端设计和实现
hua qiu
Uliweb设计分享
Uliweb设计分享
modou li
Javascript之昨是今非
Javascript之昨是今非
Tony Deng
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
Wade Huang
JdonFramework中文
JdonFramework中文
banq jdon
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.x
Bo-Yi Wu
CRUD 綜合運用
CRUD 綜合運用
Shengyou Fan
Kissy模块化实践
Kissy模块化实践
yiming he
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
fangdeng
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
wtxidian
Kindeditor设计思路v2
Kindeditor设计思路v2
luolonghao
Spring 2.x 中文
Spring 2.x 中文
Guo Albert
Chapter 4 models
Chapter 4 models
Ekman Hsieh
Nginx使用和模块开发
Nginx使用和模块开发
qingpiao1983
快快樂樂學會 Angular 2 網站開發框架 (Modern Web 2016)
快快樂樂學會 Angular 2 網站開發框架 (Modern Web 2016)
Will Huang
2023-netconf-deploy-azure-function-with-KEDA-on-aks
2023-netconf-deploy-azure-function-with-KEDA-on-aks
Roberson Liou
掌星 移动互联网开发笔记-Vol001
掌星 移动互联网开发笔记-Vol001
rainx1982
山頂洞人日記 - 回歸到最純樸的開發
山頂洞人日記 - 回歸到最純樸的開發
koji lin
Similar to Backbone js and requirejs
(20)
Django development
Django development
Introduction to CodeIgniter
Introduction to CodeIgniter
旺铺前端设计和实现
旺铺前端设计和实现
Uliweb设计分享
Uliweb设计分享
Javascript之昨是今非
Javascript之昨是今非
Asp.net mvc網站的從無到有
Asp.net mvc網站的從無到有
JdonFramework中文
JdonFramework中文
Introduction to MVC of CodeIgniter 2.1.x
Introduction to MVC of CodeIgniter 2.1.x
CRUD 綜合運用
CRUD 綜合運用
Kissy模块化实践
Kissy模块化实践
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
J engine -构建高性能、可监控的前端应用框架
Kindeditor设计思路v2
Kindeditor设计思路v2
Spring 2.x 中文
Spring 2.x 中文
Chapter 4 models
Chapter 4 models
Nginx使用和模块开发
Nginx使用和模块开发
快快樂樂學會 Angular 2 網站開發框架 (Modern Web 2016)
快快樂樂學會 Angular 2 網站開發框架 (Modern Web 2016)
2023-netconf-deploy-azure-function-with-KEDA-on-aks
2023-netconf-deploy-azure-function-with-KEDA-on-aks
掌星 移动互联网开发笔记-Vol001
掌星 移动互联网开发笔记-Vol001
山頂洞人日記 - 回歸到最純樸的開發
山頂洞人日記 - 回歸到最純樸的開發
Backbone js and requirejs
1.
Backbone.js and RequireJS 為何需要
Backbone 與 requireJS ● RequireJS ● Project 檔案架構 ● 自訂 Backbone Class ● Router ● Model ● Collection ● View ●
2.
一 . 為何需要
BackboneJS 與 RequireJS ● 使用 Backbone 將程式結構化 將一堆的 js function, 依照 MVC 架構切割成一個個的 Class 物件 ● 使用 RequireJS 將物件模組化 將產生的 Class 物件包裝成一個個獨立檔案的 Module ,去除物件與物件 間的直接關連性 ● 減少 Global 變數存在 ● 使用 RequireJS 做檔案最佳化 使用 Optimizer, 將所有檔案壓縮並 compile 成單一檔案
3.
二 .RequireJS ●
使用 <script data-main="main" src="require.js"></script> ● 程式進入點 ● 1. 設定 require.config() baseUrl : 設定所有 js 找檔案的 root 節點, 預設是 main.js 所在路徑 paths : 對檔案或目錄,設定別名在 module 中使用 urlArgs : 可在 runtime 時替所有 js 都加入 string , 避免 JS Cache ● 2. 執行 app 邏輯 require([],function(){}) 把在 project 內需要共同監聽的物件在這裡產生 instance 並設定到 App 內讓需要的物件可以參考
4.
二 .RequireJS ●
Module 定義 1. define(['_Underscore','_backbone','_$'],function(_,Backbone,$){ return { } }) 2. define(function(require){ var $ = require('_$'), _ = require('_Underscore'); return { } })
5.
二 .RequireJS ●
Module 應用模式 1.singleton instance 定義 App.js define([],function(){ return {....} }) 使用 App.initialize(); 2.Use Class 定義 MyView.js define(['_backbone'],function(Backbone){ return Backbone.View.extend({}) }) 使用 var myView=new MyView();
6.
三 .Project 檔案架構 ●
main.js : project 的進入點 ● app.js : 初始化 App 產生所有要用 Module 的 instance ● router.js : 使用者 url 經過 router 處理 , 呼叫對應要執行的 function ● text.js 與 order.js 是 RequireJS 的 Plugin, 若有用到則放在這裡 ● views/,collections/,models/ : Backbone 產生的各個物件 , 包成 Module 後 , 分別放入各個目錄內 ● templates/ : 要提供給 view render 使用的 html 樣板檔案 ● libs/ : 會用到的各種外部 resource lib 放在這裡,如 jQuery..
7.
四 . 自訂
Backbone Class ● 自訂 Class framework 內已經定義好所有的基礎 Class, 依照需要 extend 相關 Class 即可 例 MyRouter=Backbone.Router.extend({..}) MyModel==Backbone.Model.extend({..}) MyView==Backbone.View.extend({..}) ● initialize initialize 會在 new instance 時被自動執行 new instance 要傳進去的 option 設定都會被傳到這處理 ● 使用 _.bindAll 將 module 內設定的 function bind 到 Module 上使用 this 來呼叫才會有效
8.
五 .Router
在 routes 設定規則,以 URL 決定要呼叫執行的 functon ● 設定 "/login" :"loginPage" 當網址是 localhost/myproject/#/login 會執行 router 裡面的 loginPage() ● 設定 "/prod/:id" :"prodPage" 當網址是 localhost/myproject/#/prod/3 會執行 prodPage(id), 並得到一個 id=3 的參數
9.
六 .Model ●
當作一般資料儲存物件 var model=new Backbone.Model({ x:123, y:456 }) ● 可自行與 Server 溝通取得資料 以 model.fetch() 取得資料 , 資料會儲存在 model 內 , 再透過 model 提供 的 function 操作 var Item=Backbone.Model.extend({ url:function(){ return "xxx.php?id="+this.get("id"); } }); var item=new Item(); item.fetch()
10.
六 .Model ●
可被監聽 利用 model.set() 儲存變數值,則可針對這變數做監聽 var myModel=new Backbone.Model({ x:123, y:456 }) var view=new Backbone.View({ model:myModel, initialize:function(){ model.on('change:x',this.onChangeHandler) }, onChangeHandler:function(){ } })
11.
六 .Model ●
使用模式 當做 Collection 取得大批資料後儲存的資料格式 取代 global 變數,將 model 當做共用資料物件 , 監聽 model 內值變化 ● 重要性質 id: cid:系統自動產生的唯一値 attributes: 在這裡的資料才可被監聽 url: 處理產生要與 server 取得資料的 url 路徑 parse: 可改寫這部分,對接收到值做加工處理 sync: 改寫這部分,可以讓 CRUD 使用不同 URL
12.
七 .Collection 用來取得批次資料 ,
儲存資料在 collection 內大多數屬性與 model 相同 1.collection.get(id) 取得指定 id 的 model 物件 2.at(index) 取得指定 index 的 model 物件 3.length 取得 collection 內 model 的數量 4.collection.models:array 直接取得 models array
13.
八 .View
用來產生頁面元件 , 並直接接收與使用者互動的 event ● 產生 instance options 資料到帶到 initialize 內,部分特定屬性同時也會寫到 view 的屬性 上 如 model, collection, el, id, className, and tagName ● 重要性質 el: 產生 view instance 時 , 設定要指到實體的 dom 物件 , 值的設定是 selector 字串 var homePageHeader = new HomePageHeaderView({ el: "#homeHeader", }) $el:jQuery 包裝好的 el 元素 , 可以 jQuery function 操作 this.$el.empty() $: view.$(selector) 可以使用 jQuery 在 view 內部操作 this.$(".title").text() render: 預設會在這裡產生 html, 依照需求改寫
14.
八 .View
使用 Underscore 的 Template ● 載入樣板檔案 透過 requireJS 的 text plugin 載入 ● 使用 underscore template var data = { items: models, _: _ }; var _html = _.template(tmplFile, data); this.$el.append(_html);
Download now