SlideShare a Scribd company logo
1 of 14
Download to read offline
Knockout 從零開始,實戰教學
Jerry Chiang
http://www.dotblogs.com.tw/lastsecret
2012 微軟最有價值專家(C#)
twMVC 聯合創辦人之一
現職於TutorABC
2
講者簡介
Jerry Chiang
http://www.dotblogs.com.tw/lastsecret
 Blog  http://www.dotblogs.com.tw/lastsecret
 Facebook  https://www.facebook.com/lastsecret628
 Plurk  http://www.plurk.com/lastsecret
 Email  lastsecret628@gmail.com
3
聯絡我
Knockout?是什麼?
為什麼要使用Knockout?什麼專案下使用?
範例講解,Knockout威力展示。
自己動作做,30分鐘了解Knockout基本用法。
4
大綱
 Knockout 是一個 JavaScript 的 Library,透過他所提
供的 MVVM 模式的雙向綁定,可幫助建置一個乾淨、即時反
應的UI。
 題外話,什麼是MVVM?
 由Model、View 及 ViewModel 所構成的架構,透過一些機制
使 View 與 ViewModel 之間做綁定或識別,建立起 Model
與 View 之間的溝通管道。
5
Knockout?是什麼?
 簡化頁面綁定資料的複雜度
 簡化頁面綁定事件的相依性
 動態、即時的反應在UI上
 便於透過資料動態決定 DOM 的屬性、結構
 使用範本的概念,讓動態的HTML更簡潔好維護。
6
為什麼要使用Knockout?什麼專案下使用?
 頁面上只要控制View,其他資料來源都來自於外部
 大量的 UI 操作
 複雜的資料綁定
講者貼心叮嚀:
若此網站為一個獨立,且不需跟外部溝通即可完成的完整網站,
建議好好透過 MVC 的架構撰寫即可。(大量使用AJAX除外)
7
為什麼要使用Knockout?什麼專案下使用?
 只要知道一個 function 就可以進入 Knockout 的世界
ko.applyBindings()
8
範例講解,Knockout威力展示
 太無聊嗎? 那在加幾個。
 ko.observable()
 ko.observableArray()
data-bind=“text:Property”
data-bind=“value:Property”
data-bind=“foreach:ArrayProperty”
9
範例講解,Knockout威力展示
10
範例講解,Knockout威力展示
步驟:
1. 撰寫 ViewModel
2. 對 HTML 元素做Model Binding
3. ko.applyBindings()
4. 操作 ViewModel
11
範例講解,Knockout威力展示
http://twmvc10.mvc.tw
12
自己動作做,30分鐘了解Knockout基本用法
http://mvc10.hexdigits.com
 九九乘法表解答
 http://embed.plnkr.co/gT85dBvzEUXhbp2EIF8H/preview
13
自己動作做,30分鐘了解Knockout基本用法
謝謝各位
• 本投影片所包含的商標與文字皆屬原著作者所有。
• 本投影片使用的圖片皆從網路搜尋。
• 本著作係採用 Creative Commons 姓名標示-非商業性-相同方式分享 3.0 台灣 (中華民國) 授權條款授權。
h t t p : / / m v c . t w

More Related Content

Similar to twMVC#10 | Knockout 從零開始,實戰教學

twMVC#21 | 你所不知道的 Visual Studio
twMVC#21 | 你所不知道的 Visual StudiotwMVC#21 | 你所不知道的 Visual Studio
twMVC#21 | 你所不知道的 Visual StudiotwMVC
 
理財機器人技術簡介與實作經驗分享
理財機器人技術簡介與實作經驗分享理財機器人技術簡介與實作經驗分享
理財機器人技術簡介與實作經驗分享Philip Zheng
 
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3twMVC
 
twMVC#03 | ASP.NET MVC內建驗證活用與擴充
twMVC#03 | ASP.NET MVC內建驗證活用與擴充twMVC#03 | ASP.NET MVC內建驗證活用與擴充
twMVC#03 | ASP.NET MVC內建驗證活用與擴充twMVC
 
twMVC#13 | ASP.NET MVC 分頁與排序相關技巧
twMVC#13 | ASP.NET MVC 分頁與排序相關技巧twMVC#13 | ASP.NET MVC 分頁與排序相關技巧
twMVC#13 | ASP.NET MVC 分頁與排序相關技巧twMVC
 
一個微信專案從0到000的效能調教
一個微信專案從0到000的效能調教一個微信專案從0到000的效能調教
一個微信專案從0到000的效能調教Bruce Chen
 
物件導向程式設計課程講義(98 ges hi版)
物件導向程式設計課程講義(98 ges hi版)物件導向程式設計課程講義(98 ges hi版)
物件導向程式設計課程講義(98 ges hi版)Hui-Shih Leng
 
Trading bot演算法與軟工在程式交易上的實踐
Trading bot演算法與軟工在程式交易上的實踐Trading bot演算法與軟工在程式交易上的實踐
Trading bot演算法與軟工在程式交易上的實踐Philip Zheng
 
程式人雜誌 -- 2013年3月號
程式人雜誌 -- 2013年3月號程式人雜誌 -- 2013年3月號
程式人雜誌 -- 2013年3月號鍾誠 陳鍾誠
 
prompt-simple-wfegwegerherhethrhrhrehreh.pptx
prompt-simple-wfegwegerherhethrhrhrehreh.pptxprompt-simple-wfegwegerherhethrhrhrehreh.pptx
prompt-simple-wfegwegerherhethrhrhrehreh.pptxGVRao8
 
專案分層架構 twMVC#18
專案分層架構 twMVC#18專案分層架構 twMVC#18
專案分層架構 twMVC#18twMVC
 
twMVC#18 | 專案分層架構
twMVC#18 | 專案分層架構twMVC#18 | 專案分層架構
twMVC#18 | 專案分層架構twMVC
 
twMVC#24 | 開發團隊的敏捷之路(未完成)
twMVC#24 | 開發團隊的敏捷之路(未完成)twMVC#24 | 開發團隊的敏捷之路(未完成)
twMVC#24 | 開發團隊的敏捷之路(未完成)twMVC
 
面向模式的软件体系架构
面向模式的软件体系架构面向模式的软件体系架构
面向模式的软件体系架构Weijun Zhong
 
视觉智造现场培训课程简报(www.DrawSee.org)
视觉智造现场培训课程简报(www.DrawSee.org)视觉智造现场培训课程简报(www.DrawSee.org)
视觉智造现场培训课程简报(www.DrawSee.org)Redman
 
A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018Juggernaut Liu
 

Similar to twMVC#10 | Knockout 從零開始,實戰教學 (16)

twMVC#21 | 你所不知道的 Visual Studio
twMVC#21 | 你所不知道的 Visual StudiotwMVC#21 | 你所不知道的 Visual Studio
twMVC#21 | 你所不知道的 Visual Studio
 
理財機器人技術簡介與實作經驗分享
理財機器人技術簡介與實作經驗分享理財機器人技術簡介與實作經驗分享
理財機器人技術簡介與實作經驗分享
 
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3
ASP.NET MVC 內建驗證擴充與活用技巧 -twMVC#3
 
twMVC#03 | ASP.NET MVC內建驗證活用與擴充
twMVC#03 | ASP.NET MVC內建驗證活用與擴充twMVC#03 | ASP.NET MVC內建驗證活用與擴充
twMVC#03 | ASP.NET MVC內建驗證活用與擴充
 
twMVC#13 | ASP.NET MVC 分頁與排序相關技巧
twMVC#13 | ASP.NET MVC 分頁與排序相關技巧twMVC#13 | ASP.NET MVC 分頁與排序相關技巧
twMVC#13 | ASP.NET MVC 分頁與排序相關技巧
 
一個微信專案從0到000的效能調教
一個微信專案從0到000的效能調教一個微信專案從0到000的效能調教
一個微信專案從0到000的效能調教
 
物件導向程式設計課程講義(98 ges hi版)
物件導向程式設計課程講義(98 ges hi版)物件導向程式設計課程講義(98 ges hi版)
物件導向程式設計課程講義(98 ges hi版)
 
Trading bot演算法與軟工在程式交易上的實踐
Trading bot演算法與軟工在程式交易上的實踐Trading bot演算法與軟工在程式交易上的實踐
Trading bot演算法與軟工在程式交易上的實踐
 
程式人雜誌 -- 2013年3月號
程式人雜誌 -- 2013年3月號程式人雜誌 -- 2013年3月號
程式人雜誌 -- 2013年3月號
 
prompt-simple-wfegwegerherhethrhrhrehreh.pptx
prompt-simple-wfegwegerherhethrhrhrehreh.pptxprompt-simple-wfegwegerherhethrhrhrehreh.pptx
prompt-simple-wfegwegerherhethrhrhrehreh.pptx
 
專案分層架構 twMVC#18
專案分層架構 twMVC#18專案分層架構 twMVC#18
專案分層架構 twMVC#18
 
twMVC#18 | 專案分層架構
twMVC#18 | 專案分層架構twMVC#18 | 專案分層架構
twMVC#18 | 專案分層架構
 
twMVC#24 | 開發團隊的敏捷之路(未完成)
twMVC#24 | 開發團隊的敏捷之路(未完成)twMVC#24 | 開發團隊的敏捷之路(未完成)
twMVC#24 | 開發團隊的敏捷之路(未完成)
 
面向模式的软件体系架构
面向模式的软件体系架构面向模式的软件体系架构
面向模式的软件体系架构
 
视觉智造现场培训课程简报(www.DrawSee.org)
视觉智造现场培训课程简报(www.DrawSee.org)视觉智造现场培训课程简报(www.DrawSee.org)
视觉智造现场培训课程简报(www.DrawSee.org)
 
A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018A dev ops team's practice in trend micro in agile summit 2018
A dev ops team's practice in trend micro in agile summit 2018
 

More from twMVC

twMVC 47_Elastic APM 的兩三事
twMVC 47_Elastic APM 的兩三事twMVC 47_Elastic APM 的兩三事
twMVC 47_Elastic APM 的兩三事twMVC
 
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning ServicestwMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning ServicestwMVC
 
.NET 7 家族新成員: Microsoft Orleans v7
.NET 7 家族新成員:Microsoft Orleans v7.NET 7 家族新成員:Microsoft Orleans v7
.NET 7 家族新成員: Microsoft Orleans v7twMVC
 
twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇twMVC
 
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC
 
twMVC#44 讓我們用 k6 來進行壓測吧
twMVC#44 讓我們用 k6 來進行壓測吧twMVC#44 讓我們用 k6 來進行壓測吧
twMVC#44 讓我們用 k6 來進行壓測吧twMVC
 
twMVC#43 Visual Studio 2022 新功能拆解
twMVC#43 Visual Studio 2022 新功能拆解twMVC#43 Visual Studio 2022 新功能拆解
twMVC#43 Visual Studio 2022 新功能拆解twMVC
 
twMVC#43 YARP
twMVC#43 YARPtwMVC#43 YARP
twMVC#43 YARPtwMVC
 
twMVC#43 C#10 新功能介紹
twMVC#43 C#10 新功能介紹twMVC#43 C#10 新功能介紹
twMVC#43 C#10 新功能介紹twMVC
 
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用twMVC
 
twMVC#42 Azure IoT Hub for Smart Factory
twMVC#42 Azure IoT Hub for Smart FactorytwMVC#42 Azure IoT Hub for Smart Factory
twMVC#42 Azure IoT Hub for Smart FactorytwMVC
 
twMVC#42 Windows容器導入由0到1
twMVC#42 Windows容器導入由0到1twMVC#42 Windows容器導入由0到1
twMVC#42 Windows容器導入由0到1twMVC
 
twMVC#42 讓我們用一種方式來開發吧
twMVC#42 讓我們用一種方式來開發吧twMVC#42 讓我們用一種方式來開發吧
twMVC#42 讓我們用一種方式來開發吧twMVC
 
twMVC#41 hololens2 MR
twMVC#41 hololens2 MRtwMVC#41 hololens2 MR
twMVC#41 hololens2 MRtwMVC
 
twMVC#41 The journey of source generator
twMVC#41 The journey of source generatortwMVC#41 The journey of source generator
twMVC#41 The journey of source generatortwMVC
 
twMVC#38 How we migrate tfs to git(using azure dev ops)
twMVC#38 How we migrate tfs to git(using azure dev ops) twMVC#38 How we migrate tfs to git(using azure dev ops)
twMVC#38 How we migrate tfs to git(using azure dev ops) twMVC
 
twMVC#36C#的美麗與哀愁
twMVC#36C#的美麗與哀愁twMVC#36C#的美麗與哀愁
twMVC#36C#的美麗與哀愁twMVC
 
twMVC#36.NetCore 3快速看一波
twMVC#36.NetCore 3快速看一波twMVC#36.NetCore 3快速看一波
twMVC#36.NetCore 3快速看一波twMVC
 
twMVC#36讓 Exceptionless 存管你的 Log
twMVC#36讓 Exceptionless 存管你的 LogtwMVC#36讓 Exceptionless 存管你的 Log
twMVC#36讓 Exceptionless 存管你的 LogtwMVC
 
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API twMVC
 

More from twMVC (20)

twMVC 47_Elastic APM 的兩三事
twMVC 47_Elastic APM 的兩三事twMVC 47_Elastic APM 的兩三事
twMVC 47_Elastic APM 的兩三事
 
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning ServicestwMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
twMVC#46_SQL Server 資料分析大躍進 Machine Learning Services
 
.NET 7 家族新成員: Microsoft Orleans v7
.NET 7 家族新成員:Microsoft Orleans v7.NET 7 家族新成員:Microsoft Orleans v7
.NET 7 家族新成員: Microsoft Orleans v7
 
twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇
 
twMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwrighttwMVC#44 如何測試與保護你的 web application with playwright
twMVC#44 如何測試與保護你的 web application with playwright
 
twMVC#44 讓我們用 k6 來進行壓測吧
twMVC#44 讓我們用 k6 來進行壓測吧twMVC#44 讓我們用 k6 來進行壓測吧
twMVC#44 讓我們用 k6 來進行壓測吧
 
twMVC#43 Visual Studio 2022 新功能拆解
twMVC#43 Visual Studio 2022 新功能拆解twMVC#43 Visual Studio 2022 新功能拆解
twMVC#43 Visual Studio 2022 新功能拆解
 
twMVC#43 YARP
twMVC#43 YARPtwMVC#43 YARP
twMVC#43 YARP
 
twMVC#43 C#10 新功能介紹
twMVC#43 C#10 新功能介紹twMVC#43 C#10 新功能介紹
twMVC#43 C#10 新功能介紹
 
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
twMVC#42 Azure DevOps Service Pipeline設計與非正常應用
 
twMVC#42 Azure IoT Hub for Smart Factory
twMVC#42 Azure IoT Hub for Smart FactorytwMVC#42 Azure IoT Hub for Smart Factory
twMVC#42 Azure IoT Hub for Smart Factory
 
twMVC#42 Windows容器導入由0到1
twMVC#42 Windows容器導入由0到1twMVC#42 Windows容器導入由0到1
twMVC#42 Windows容器導入由0到1
 
twMVC#42 讓我們用一種方式來開發吧
twMVC#42 讓我們用一種方式來開發吧twMVC#42 讓我們用一種方式來開發吧
twMVC#42 讓我們用一種方式來開發吧
 
twMVC#41 hololens2 MR
twMVC#41 hololens2 MRtwMVC#41 hololens2 MR
twMVC#41 hololens2 MR
 
twMVC#41 The journey of source generator
twMVC#41 The journey of source generatortwMVC#41 The journey of source generator
twMVC#41 The journey of source generator
 
twMVC#38 How we migrate tfs to git(using azure dev ops)
twMVC#38 How we migrate tfs to git(using azure dev ops) twMVC#38 How we migrate tfs to git(using azure dev ops)
twMVC#38 How we migrate tfs to git(using azure dev ops)
 
twMVC#36C#的美麗與哀愁
twMVC#36C#的美麗與哀愁twMVC#36C#的美麗與哀愁
twMVC#36C#的美麗與哀愁
 
twMVC#36.NetCore 3快速看一波
twMVC#36.NetCore 3快速看一波twMVC#36.NetCore 3快速看一波
twMVC#36.NetCore 3快速看一波
 
twMVC#36讓 Exceptionless 存管你的 Log
twMVC#36讓 Exceptionless 存管你的 LogtwMVC#36讓 Exceptionless 存管你的 Log
twMVC#36讓 Exceptionless 存管你的 Log
 
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
twMVC#33聊聊如何自建 Facebook {廣告} 服務 with API
 

twMVC#10 | Knockout 從零開始,實戰教學