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網頁應用程式設計
240
|
第十三章
假設我們希望在有人新增一筆 task 時,能夠接獲通知,好讓我們能夠即時將這筆新的
task 資料加進網頁裡。而且在加進網頁後,還要能監聽該筆 task 的所有變動,藉此確保
顯示的名稱是正確的。可以這麼寫:
Task.bind('created', function(ev, task){
var el = $('<li>').html(task.name);
el.appendTo($('#todos'));
task.bind('updated', function(){
el.html(this.name);
}).bind('destroyed', function(){
el.remove();
})
});
在檢視器裡使用用戶端模版
JavaScriptMVC 的檢視器,其實就是用戶端模版。它會接收一些資料,並回傳一組字
串。檢視器所回傳的字串,基本上就是要被用來加進 DOM 元件的 HTML 程式碼。
$.View
是產生模版內容的程式介面,它利用模版降低程式的複雜度。其特色包括:
容易使用且一致的語法
可從 HTML 元件或外部檔案載入模版
可透過同步或非同步方式載入模版
可預先載入模版
可將處理過的模版存入快取
可將處理過的模版包進正式環境的建置版本中
支援
$.Deferred
JavaScriptMVC 已經納入四種不同的模版引擎:
EJS
JAML
Micro
Tmpl
雖然接下來的說明是採用 EJS 模版,不過大部分的概念適用於任何一種模版引擎(只是 ...
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