SlideShare a Scribd company logo
1 of 24
KNOCKOUT.JS
Scott Messinger - Baltimore JS Meetup - July 27, 2011
WHO AM I?
WHAT IS KNOCKOUT.JS?
MODEL/VIEW/VIEWMODEL
        MVVM
Pretty Pictures.




DB               DB
KO AUTOMATICALLY
UPDATES YOUR DOM.
HISTORY
MICROSOFT. SILVERLIGHT.
        WPF.
LET’S CHECK IT OUT.
PART 1: CONTACT EDITOR.
 HTTP://JSBIN.COM/UVUBEM/6/EDIT
PART 2:
      TO DO LIST
http://jsfiddle.net/scottmessinger/pC4zY/16/
LET ME SHOW YOU AROUND.
TASK 1:
 SHOW SOME TODOS
     http://jsfiddle.net/scottmessinger/RtGyu/5/
http://knockoutjs.com/documentation/introduction.html
Do the highlights.
                                 Add “todo done” classes if done
                                    Add “todo” if not done.
      <script id="todoitemtemplate"type="text/html">
        <li>
          <div data-bind="">
            <div class="display">
              <input class="check"type="checkbox" data-bind="" />
              <div class="todo-content"contenteditable="true" data-bind=""></div>
              <span class="todo-destroy" data-bind=""></span>
            </div>
          </div>
        </li>
      </script>
      


                     http://jsfiddle.net/scottmessinger/RtGyu/5/
The answer!
      <ul id="todo-list" data-bind="template: { name: 'todoitemtemplate', foreach: todos }">
      </ul>
      <script id="todoitemtemplate"type="text/html">
        <li>
          <div data-bind="attr: { class : done() ? 'todo done' : 'todo'}">
            <div class="display">
              <input class="check"type="checkbox" data-bind="checked: done" />
              <div class="todo-content"contenteditable="true" data-bind="text: content"></di
              <span class="todo-destroy" data-bind="click: viewModel.remove"></span>
            </div>
          </div>
        </li>
      </script>
TASK 2:
REMOVE SOME TODOS
        http://jsfiddle.net/scottmessinger/RtGyu/5/

http://knockoutjs.com/documentation/introduction.html
Do the highlights.
         
        <div id="todo-stats" >
         
            // CODE
         
            <span class="todo-clear" data-bind="visible: done().length > 0">
         
              <a href="#" data-bind="">
               // CODE
              </a>
            </span>
        </div>


              <script id="todoitemtemplate"type="text/html">
                <li>
                  <div data-bind="attr: { class : done() ? 'todo done' : 'todo'}">
                    <div class="display">
                      <input class="check"type="checkbox" data-bind="checked: done" />
                      <div class="todo-content"contenteditable="true" data-bind="text: content"></div>
                      <span class="todo-destroy" data-bind=""></span>
                    </div>
                  </div>
                </li>
              </script>
Do the highlights.
         
        <div id="todo-stats" >
         
            // CODE
         
            <span class="todo-clear" data-bind="visible: done().length > 0">
         
              <a href="#" data-bind="click: viewModel.removeCompleted">
               // CODE
              </a>
            </span>
        </div>


              <script id="todoitemtemplate"type="text/html">
                <li>
                  <div data-bind="attr: { class : done() ? 'todo done' : 'todo'}">
                    <div class="display">
                      <input class="check"type="checkbox" data-bind="checked: done" />
                      <div class="todo-content"contenteditable="true" data-bind="text: content"></div>
                      <span class="todo-destroy" data-bind="click: viewModel.remove"></span>
                    </div>
                  </div>
                </li>
              </script>
Do the highlights
// VIEWMODEL
var viewModel = {
    todos: ko.observableArray(),
    current: ko.observable(),
    add: function (event) {
        if (event.keyCode === 13) {
            var newTodo = new Todo(this.current());
            this.todos.push(newTodo);                  Methods to
            console.log(newTodo)
                                                         Know:
            this.current("");
        }
    },                                                  remove()
                                                       removeAll()
    remove: function (event) {
        viewModel.todos.remove(this);
    },

    removeCompleted: function (event) {
        viewModel.todos.removeAll(viewModel.done());
    }
};
Do the highlights
// VIEWMODEL
var viewModel = {
    todos: ko.observableArray(),
    current: ko.observable(),
    add: function (event) {
        if (event.keyCode === 13) {
            var newTodo = new Todo(this.current());
            this.todos.push(newTodo);                 Methods to
            console.log(newTodo)                        Know:
            this.current("");
        }
    },
                                                       remove()

    remove: function (event) {                        removeAll()
    },

    removeCompleted: function (event) {

    }
};
PROBLEMS WITH MVVM
CODE WALK
https://gist.github.com/1109917
Learning more about
          knockout.js
knockoutjs.com

knockmeout.net

https://groups.google.com/
forum/#!forum/knockoutjs
QUESTIONS.

More Related Content

What's hot

AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig
 

What's hot (20)

Backbone js
Backbone jsBackbone js
Backbone js
 
Dom selecting & jQuery
Dom selecting & jQueryDom selecting & jQuery
Dom selecting & jQuery
 
React 소개 및 구현방법 Demo
React 소개 및 구현방법 DemoReact 소개 및 구현방법 Demo
React 소개 및 구현방법 Demo
 
Data binding w Androidzie
Data binding w AndroidzieData binding w Androidzie
Data binding w Androidzie
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Modern frontend development with VueJs
Modern frontend development with VueJsModern frontend development with VueJs
Modern frontend development with VueJs
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Client Web
Client WebClient Web
Client Web
 
Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014Modern Web Application Development Workflow - EclipseCon Europe 2014
Modern Web Application Development Workflow - EclipseCon Europe 2014
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
React
React React
React
 
Why and How to Use Virtual DOM
Why and How to Use Virtual DOMWhy and How to Use Virtual DOM
Why and How to Use Virtual DOM
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
Levent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & PolymerLevent-Gurses' Introduction to Web Components & Polymer
Levent-Gurses' Introduction to Web Components & Polymer
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Week 8
Week 8Week 8
Week 8
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Web Components
Web ComponentsWeb Components
Web Components
 

Viewers also liked

An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
hchen1
 

Viewers also liked (20)

An introduction to knockout.js
An introduction to knockout.jsAn introduction to knockout.js
An introduction to knockout.js
 
Introduction to Knockoutjs
Introduction to KnockoutjsIntroduction to Knockoutjs
Introduction to Knockoutjs
 
Knockout.js explained
Knockout.js explainedKnockout.js explained
Knockout.js explained
 
Wcf
WcfWcf
Wcf
 
jQuery in 10 minuten
jQuery in 10 minutenjQuery in 10 minuten
jQuery in 10 minuten
 
Knockout js
Knockout jsKnockout js
Knockout js
 
Knockout js (Dennis Haney)
Knockout js (Dennis Haney)Knockout js (Dennis Haney)
Knockout js (Dennis Haney)
 
knockout.js
knockout.jsknockout.js
knockout.js
 
Knockout (support slides for presentation)
Knockout (support slides for presentation)Knockout (support slides for presentation)
Knockout (support slides for presentation)
 
Knockout.js
Knockout.jsKnockout.js
Knockout.js
 
Knockout js
Knockout jsKnockout js
Knockout js
 
Asp.Net MVC - Razor Syntax
Asp.Net MVC - Razor SyntaxAsp.Net MVC - Razor Syntax
Asp.Net MVC - Razor Syntax
 
HTML 5, ASP.NET MVC & Windows Azure sessie voor Ivo Brugge
HTML 5, ASP.NET MVC & Windows Azure sessie voor Ivo BruggeHTML 5, ASP.NET MVC & Windows Azure sessie voor Ivo Brugge
HTML 5, ASP.NET MVC & Windows Azure sessie voor Ivo Brugge
 
Knockout JS Development - a Quick Understanding
Knockout JS Development - a Quick UnderstandingKnockout JS Development - a Quick Understanding
Knockout JS Development - a Quick Understanding
 
Knockout js
Knockout jsKnockout js
Knockout js
 
#2 Hanoi Magento Meetup - Part 2: Knockout JS
#2 Hanoi Magento Meetup - Part 2: Knockout JS#2 Hanoi Magento Meetup - Part 2: Knockout JS
#2 Hanoi Magento Meetup - Part 2: Knockout JS
 
An Introduction to Ajax Programming
An Introduction to Ajax ProgrammingAn Introduction to Ajax Programming
An Introduction to Ajax Programming
 
Design for Developers: Introduction to Bootstrap 3
Design for Developers: Introduction to Bootstrap 3Design for Developers: Introduction to Bootstrap 3
Design for Developers: Introduction to Bootstrap 3
 
Ajax Ppt
Ajax PptAjax Ppt
Ajax Ppt
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 

Similar to Knockout.js presentation

Private slideshow
Private slideshowPrivate slideshow
Private slideshow
sblackman
 
Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007
Netvibes
 
Vidéo approche en immobilier
Vidéo approche en immobilierVidéo approche en immobilier
Vidéo approche en immobilier
hervepouliot
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
OSCON Byrum
 
Elinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkej
Elinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkejElinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkej
Elinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkej
Pertti Paavola
 

Similar to Knockout.js presentation (20)

Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
Django quickstart
Django quickstartDjango quickstart
Django quickstart
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshow
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Xxx
XxxXxx
Xxx
 
Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007Netvibes UWA workshop at ParisWeb 2007
Netvibes UWA workshop at ParisWeb 2007
 
Single page webapps & javascript-testing
Single page webapps & javascript-testingSingle page webapps & javascript-testing
Single page webapps & javascript-testing
 
Vidéo approche en immobilier
Vidéo approche en immobilierVidéo approche en immobilier
Vidéo approche en immobilier
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Clean Javascript
Clean JavascriptClean Javascript
Clean Javascript
 
course js day 3
course js day 3course js day 3
course js day 3
 
Stole16
Stole16Stole16
Stole16
 
JavaScript Refactoring
JavaScript RefactoringJavaScript Refactoring
JavaScript Refactoring
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
How to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI ComponentsHow to Mess Up Your Angular UI Components
How to Mess Up Your Angular UI Components
 
Elinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkej
Elinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkejElinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkej
Elinvoimaa hunajasta-yleist-hunajatietoa-ja-kyttvinkkej
 
Meteor Day Talk
Meteor Day TalkMeteor Day Talk
Meteor Day Talk
 
前端概述
前端概述前端概述
前端概述
 

Recently uploaded

Recently uploaded (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Knockout.js presentation

  • 1. KNOCKOUT.JS Scott Messinger - Baltimore JS Meetup - July 27, 2011
  • 10. PART 1: CONTACT EDITOR. HTTP://JSBIN.COM/UVUBEM/6/EDIT
  • 11. PART 2: TO DO LIST http://jsfiddle.net/scottmessinger/pC4zY/16/
  • 12. LET ME SHOW YOU AROUND.
  • 13. TASK 1: SHOW SOME TODOS http://jsfiddle.net/scottmessinger/RtGyu/5/ http://knockoutjs.com/documentation/introduction.html
  • 14. Do the highlights. Add “todo done” classes if done Add “todo” if not done.     <script id="todoitemtemplate"type="text/html">       <li>         <div data-bind="">           <div class="display">             <input class="check"type="checkbox" data-bind="" />             <div class="todo-content"contenteditable="true" data-bind=""></div>             <span class="todo-destroy" data-bind=""></span>           </div>         </div>       </li>     </script>      http://jsfiddle.net/scottmessinger/RtGyu/5/
  • 15. The answer!       <ul id="todo-list" data-bind="template: { name: 'todoitemtemplate', foreach: todos }">       </ul>     <script id="todoitemtemplate"type="text/html">       <li>         <div data-bind="attr: { class : done() ? 'todo done' : 'todo'}">           <div class="display">             <input class="check"type="checkbox" data-bind="checked: done" />             <div class="todo-content"contenteditable="true" data-bind="text: content"></di             <span class="todo-destroy" data-bind="click: viewModel.remove"></span>           </div>         </div>       </li>     </script>
  • 16. TASK 2: REMOVE SOME TODOS http://jsfiddle.net/scottmessinger/RtGyu/5/ http://knockoutjs.com/documentation/introduction.html
  • 17. Do the highlights.         <div id="todo-stats" >             // CODE             <span class="todo-clear" data-bind="visible: done().length > 0">               <a href="#" data-bind=""> // CODE               </a>             </span>         </div>     <script id="todoitemtemplate"type="text/html">       <li>         <div data-bind="attr: { class : done() ? 'todo done' : 'todo'}">           <div class="display">             <input class="check"type="checkbox" data-bind="checked: done" />             <div class="todo-content"contenteditable="true" data-bind="text: content"></div>             <span class="todo-destroy" data-bind=""></span>           </div>         </div>       </li>     </script>
  • 18. Do the highlights.         <div id="todo-stats" >             // CODE             <span class="todo-clear" data-bind="visible: done().length > 0">               <a href="#" data-bind="click: viewModel.removeCompleted"> // CODE               </a>             </span>         </div>     <script id="todoitemtemplate"type="text/html">       <li>         <div data-bind="attr: { class : done() ? 'todo done' : 'todo'}">           <div class="display">             <input class="check"type="checkbox" data-bind="checked: done" />             <div class="todo-content"contenteditable="true" data-bind="text: content"></div>             <span class="todo-destroy" data-bind="click: viewModel.remove"></span>           </div>         </div>       </li>     </script>
  • 19. Do the highlights // VIEWMODEL var viewModel = {     todos: ko.observableArray(),     current: ko.observable(),     add: function (event) {         if (event.keyCode === 13) {             var newTodo = new Todo(this.current());             this.todos.push(newTodo); Methods to             console.log(newTodo) Know:             this.current("");         }     }, remove() removeAll()     remove: function (event) {         viewModel.todos.remove(this);     },     removeCompleted: function (event) {         viewModel.todos.removeAll(viewModel.done());     } };
  • 20. Do the highlights // VIEWMODEL var viewModel = {     todos: ko.observableArray(),     current: ko.observable(),     add: function (event) {         if (event.keyCode === 13) {             var newTodo = new Todo(this.current());             this.todos.push(newTodo); Methods to             console.log(newTodo) Know:             this.current("");         }     }, remove()     remove: function (event) { removeAll()     },     removeCompleted: function (event) {     } };
  • 23. Learning more about knockout.js knockoutjs.com knockmeout.net https://groups.google.com/ forum/#!forum/knockoutjs

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n