Skip to Content
JAVASCRIPT網頁應用程式設計
book

JAVASCRIPT網頁應用程式設計

by Alex MacCaw
January 2013
Intermediate to advanced
332 pages
5h 23m
Chinese
GoTop Information, Inc.
Content preview from JAVASCRIPT網頁應用程式設計
Spine 函式庫
|
185
那麼該如何在伺服器端進行資料驗證呢? Spine 會假設用戶端已經做過所有必要的資料
驗證。伺服器端只有在發生非預期的例外事件時(程式發生問題),才會回應錯誤。
如果伺服器無法成功回覆你所送出的請求,就會觸發模型的
ajaxError
事件,該事件的回
叫函式會取得四組參數:導致錯誤發生的資料(record)、
XMLHttpRequest
物件(xhr)、
Ajax 設定值(settings),以及伺服器端拋出的錯誤(error):
Task.bind("ajaxError", function(record, xhr, settings, error){
// 伺服器無法成功回覆請求
});
控制器
最後一個要介紹的 Spine 元件,就是控制器。它就像是接著劑一樣,將應用程式其他
的部分黏合在一起。一般來說,控制器的工作包括:為 DOM 元件和模型設定事件處理
器、產生模版、讓檢視器和模型兩邊的資料保持一致。如果要建立一個 Spine 控制器,
需要呼叫
create()
來建立
Spine.Controller
的子類別:
jQuery(function(){
window.Tasks = Spine.Controller.create({
// 控制器的屬性
});
});
建議在網頁其他部分都載入完成後,才開始載入控制器。這麼一來才不用費心去處
理各種網頁元件找不到的狀況。你會發現所有的 Spine 範例程式,都會把控制器寫在
jQuery()
函式裡面。這麼做就是為了要確保在建立控制器時 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

初めてのJavaScript 第3版 ―ES2015以降の最新ウェブ開発

Ethan Brown, 武舎 広幸, 武舎 るみ
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre
Strange Code

Strange Code

Ronald T. Kneusel
Perfecting Your Thinking Skills

Perfecting Your Thinking Skills

MIT Sloan Management Review

Publisher Resources

ISBN: 9789862766811