SlideShare a Scribd company logo
Boulos Dib
September 15, 2012
MARQUEE SPONSOR
PLATINUM SPONSOR
PLATINUM SPONSOR
PLATINUM SPONSOR
GOLD SPONSORS
SILVER SPONSORS
   Independent Consultant – Napeague Inc.
   First Commercial Personal Computer 1980 – TRS-80 Model III
   First Z80 based product (Protocol Adaptor For Citibank– 1984)
   First Commercial MS-DOS product (Telex/IBM PC, 50 Baud – 1985)
   Started Windows Development using 16-bit Win 3.x
   Used: 8080/Z80, 68xxx, PDP/RSX,VAX-VMS and x86 (C, C++, C#)
   User Group/Meetup Co-Organizer:
     New York Pluralsight Study Group, XAML NYC
   Other interests:
     Windsurfing, Guitar Playing
   Introduction to Knockout & MVVM
   Built-in bindings
   Custom bindings
   Templates
   Simple development pattern.
     MVVM, aka MVVC, sometimes MVC or MVP
   Separation of concerns (Pattern)
     Separates Model and UI
     Separates Behavior and Structure
   Popular with WPF & Silverlight developers.
     Data Binding makes it easy to implement MVVM.
   The 100K foot level view, Web Application
   Models, Controllers and Views

                     Web Application
                                                           DB
       Views                Controllers       Models
        Partial Views              Routes         Services
         Partial Views              Routes          Services
            Partial Views            Routes            Services
           Code & Markup              Code              Code
   The browser level view
   HTML/CSS – JavaScript - JSON

                         Browser

       View              ViewModel              Model
     HTML & CSS           JavaScript            JSON
                  <h1>                 var x;           {a: b }
   Javascript Library to simplify dynamic UIs
    with automatic refresh.

   Core Concepts
     Declarative Bindings
     Dependency Tracking
     Templates
   Extensible
   If using ASP.NET MVC
     NuGet Package Manager


   Download
     knockoutjs
     jQuery
   Observable
   Computed Observable
   Observable Arrays
   Declarative bindings
   Template Support
   Create the Model
     Retrieve Data: usually via Ajax or other form data
     retrieval (API, LocalStorage).
   Create the ViewModel
     Encapsulate UI behavior and data from model.
   Create the View (HTML Markup)
     <label data-bind=“text: name” />
   Bind the ViewModel to the view
     applyBindings(viewModel)
var viewModel = {
        firstName: ko.observable("John"),
        lastName: ko.observable("Doe")
};
ko.applyBindings(viewModel);




First Name: <input type="text“ data-bind="value: firstName"/>
Last Name: <input type="text" data-bind=“value: lastName" />

<span data-bind="text : firstName"></span>
<input type="text" data-bind="value : lastName" />
var vm = {
   quantity: ko.observable(10),
   price: ko.observable(100),
   taxRate: ko.observable(8.75)
};

viewModel = new vm();
viewModel.totalCost = ko.computed(function () {
  return (parseInt("0" + this.quantity(), 10) * this.price()) * this.taxRate();
}, viewModel);

ko.applyBindings(viewModel);
var viewModel = {
    States: ko.observableArray([
    { State: "New York", Cities: ['New York City', 'East Hampton', 'Yonkers'] },
    { State: "New Jersey", Cities: ['Jersey City', 'Hoboken', 'Maplewood'] },
    { State: "Connecticut", Cities: ['Stamford', 'Greenwich'] },
    { State: "Pennsylvania", Cities: ['Philadelphia'] },
]),
    selectedState: ko.observable(),
    selectedCity: ko.observable()
};

viewModel.selectionMade = ko.computed(function () {
    return (this.selectedState() && this.selectedCity());
}, viewModel);
ko.applyBindings(viewModel);
Type      Description
visible   Used to hide or show DOM elements

text      Display text value in a DOM element

html      Display html in a DOM element

css       Add or remove CSS classes from DOM elements

style     Apply specific style to a DOM Element

attr      Set the value of any attribute on a DOM element
binding   Description
foreach   Used for rendering lists based on array bindings.

If        Conditional inclusion of markup and any related binding based on
          truthy condition
Ifnot     Conditional inclusion of markup and any related binding based on a
          falsey condition
with      Creates a new binding context changing what descendent element
          bind to.
binding   Description
click     Add an event handler so a function is invoked when the associated
          DOM element is clicked.
event     Add an event handler than can be bound to any event, such as
          keypress, mouseover or mouseout.
submit    Event handler used when submitting forms.

enable    Used to enable DOM elements only when the parameter value is
          true. Typically used with form elements like input, select, and
          textarea.
disable   Opposite of enable. Used in the same way.
binding           Description
value             Associates a DOM’s element value with a propery on the
                  viewmodel.
hasfocus          Two way binding for setting focus on an element and chekcing
                  whether an element has focus.
checked           This binding is used for checkable controls. Radio button or
                  checkbox.
options           Used to bind the elements of a drop-down list or multi-select list.

selectedOptions Bind to elements that are currently selected. Used with select and
                options bindings.
uniqueName        Gives an element a unique name if it does not already have a name
                  attribute.
// Subscribe
myViewModel.totalCost.subscribe(function(newValue) {
    alert(“Let’s check if we are above our budget" + newValue);
});


// Dispose of subscription
var subscriptionCost =
myViewModel.totalCost.subscribe(function(newValue) {

/* do some work   */

});

// ...then later...
subscriptionCost.dispose();
   Custom Bindings
   Plugins

   TodoMVC
     http://addyosmani.github.com/todomvc/
   Knockbackjs
     http://kmalakoff.github.com/knockback/
   KnockoutMVC
     http://knockoutmvc.com/
   Named Templates
   Anonymous Templates
   Inline
   External
   Register a binding by adding it as a
    subproperty of ko.bindingHandlers.

   Need to supply two functions:
     init
     update


   And then use it with DOM element bindings.
    <div data-bind=“customBindingName: someValue"> </div>
ko.bindingHandlers.customBindingName = {
  init: function (element, valueAccessor, allBindingsAccessor, viewModel) {

          // This will be called when the binding is first applied to an element
          // Set up any initial state, event handlers, etc. here
     },

     update: function (element, valueAccessor, allBindingsAccessor, VM) {
        // This will be called once when the binding is first
        // applied to an element, and again whenever the associated
        // observable changes value.
        // Update the DOM element based on the supplied values here.
       }

};
   Main Site (Steve Sanderson - Author)
     http://knockoutjs.com
   Ryan Niemeyer - Contributor
     http://www.knockmeout.com
   Contact:
     http://blog.boulosdib.com
     @boulosdib

More Related Content

PPTX
Knockout.js
KEY
Knockout.js presentation
PPTX
Bringing the light to the client with KnockoutJS
PPTX
Asp.NET MVC
PPTX
PPTX
Asp.net mvc training
PDF
當ZK遇見Front-End
PPTX
KnockOutjs from Scratch
Knockout.js
Knockout.js presentation
Bringing the light to the client with KnockoutJS
Asp.NET MVC
Asp.net mvc training
當ZK遇見Front-End
KnockOutjs from Scratch

What's hot (20)

PDF
Data binding w Androidzie
KEY
MVC on the server and on the client
PDF
AngularJS Basic Training
KEY
AngularJS for designers and developers
PPT
Backbone.js
PDF
From mvc to viper
PDF
Custom AngularJS Directives
PDF
MVVM Light Toolkit Works Great, Less Complicated
PDF
Backbone js
PDF
Dmytro Zaitsev Viper: make your mvp cleaner
PPTX
The AngularJS way
PDF
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
PPTX
Angular Js Basics
PDF
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
PDF
Angular custom directives
PDF
Workshop 2: JavaScript Design Patterns
PPTX
Planbox Backbone MVC
PPT
WPF Fundamentals
PPTX
Knockout js
PPTX
Integration of Backbone.js with Spring 3.1
Data binding w Androidzie
MVC on the server and on the client
AngularJS Basic Training
AngularJS for designers and developers
Backbone.js
From mvc to viper
Custom AngularJS Directives
MVVM Light Toolkit Works Great, Less Complicated
Backbone js
Dmytro Zaitsev Viper: make your mvp cleaner
The AngularJS way
Building Custom AngularJS Directives - A Step-by-Step Guide - Dan Wahlin | Fa...
Angular Js Basics
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
Angular custom directives
Workshop 2: JavaScript Design Patterns
Planbox Backbone MVC
WPF Fundamentals
Knockout js
Integration of Backbone.js with Spring 3.1
Ad

Viewers also liked (19)

PPTX
CETPA Introduction
PPT
Ape n ükotnes sp-ōle
PPT
Union of Agricultural Work Committees (UAWC) presentation
PPTX
Cell Tracking Software: What The Offer Is
PPT
Lake to Lake 2011 Jay Karen handouts
PPTX
Seattle Dev Garage
PPTX
2013 awards master (website)
PPTX
Analysis of music video's
PPTX
Draft 2 planning
PDF
Reflexio innovacio--1-2012
PPTX
Islam sebagai sebuah sistem agama
PDF
Corporate Presentation - BMO 2015 Global Metals & Mining Conference
DOCX
Tugas geoteknik tambang
PPTX
Assignment 10 group assignment final draft
PPTX
New members 11.03.15
PDF
Q4 2013 presentation final
PPT
Random 091108040922-phpapp02
DOCX
Peran k3 dalam eksplorasi tambang bawah laut 2
PPT
Use grammar with pictures feb 8 2013 (1)
CETPA Introduction
Ape n ükotnes sp-ōle
Union of Agricultural Work Committees (UAWC) presentation
Cell Tracking Software: What The Offer Is
Lake to Lake 2011 Jay Karen handouts
Seattle Dev Garage
2013 awards master (website)
Analysis of music video's
Draft 2 planning
Reflexio innovacio--1-2012
Islam sebagai sebuah sistem agama
Corporate Presentation - BMO 2015 Global Metals & Mining Conference
Tugas geoteknik tambang
Assignment 10 group assignment final draft
New members 11.03.15
Q4 2013 presentation final
Random 091108040922-phpapp02
Peran k3 dalam eksplorasi tambang bawah laut 2
Use grammar with pictures feb 8 2013 (1)
Ad

Similar to Knockoutjs databinding (20)

PPTX
Fundaments of Knockout js
PDF
MVVM & Data Binding Library
PPTX
AngularJs Workshop SDP December 28th 2014
PDF
Knockoutjs
PPTX
angularJs Workshop
PPTX
The Magic of WPF & MVVM
PDF
Knockout js session
PPTX
Introduction to XAML and its features
PDF
Angular - Chapter 4 - Data and Event Handling
PPTX
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
PPTX
Backbonejs
PPTX
Knockout js
PDF
Creating lightweight JS Apps w/ Web Components and lit-html
PDF
Web Components Everywhere
PPTX
MV* presentation frameworks in Javascript: en garde, pret, allez!
PDF
Rp 6 session 2 naresh bhatia
PPTX
Google Polymer Introduction
PPT
Diving in the Flex Data Binding Waters
PPTX
Angular Framework ppt for beginners and advanced
PPT
KnockoutJS and MVVM
Fundaments of Knockout js
MVVM & Data Binding Library
AngularJs Workshop SDP December 28th 2014
Knockoutjs
angularJs Workshop
The Magic of WPF & MVVM
Knockout js session
Introduction to XAML and its features
Angular - Chapter 4 - Data and Event Handling
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Backbonejs
Knockout js
Creating lightweight JS Apps w/ Web Components and lit-html
Web Components Everywhere
MV* presentation frameworks in Javascript: en garde, pret, allez!
Rp 6 session 2 naresh bhatia
Google Polymer Introduction
Diving in the Flex Data Binding Waters
Angular Framework ppt for beginners and advanced
KnockoutJS and MVVM

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Electronic commerce courselecture one. Pdf
PDF
Approach and Philosophy of On baking technology
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Spectral efficient network and resource selection model in 5G networks
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
A Presentation on Artificial Intelligence
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology

Knockoutjs databinding

  • 8. Independent Consultant – Napeague Inc.  First Commercial Personal Computer 1980 – TRS-80 Model III  First Z80 based product (Protocol Adaptor For Citibank– 1984)  First Commercial MS-DOS product (Telex/IBM PC, 50 Baud – 1985)  Started Windows Development using 16-bit Win 3.x  Used: 8080/Z80, 68xxx, PDP/RSX,VAX-VMS and x86 (C, C++, C#)  User Group/Meetup Co-Organizer:  New York Pluralsight Study Group, XAML NYC  Other interests:  Windsurfing, Guitar Playing
  • 9. Introduction to Knockout & MVVM  Built-in bindings  Custom bindings  Templates
  • 10. Simple development pattern.  MVVM, aka MVVC, sometimes MVC or MVP  Separation of concerns (Pattern)  Separates Model and UI  Separates Behavior and Structure  Popular with WPF & Silverlight developers.  Data Binding makes it easy to implement MVVM.
  • 11. The 100K foot level view, Web Application  Models, Controllers and Views Web Application DB Views Controllers Models Partial Views Routes Services Partial Views Routes Services Partial Views Routes Services Code & Markup Code Code
  • 12. The browser level view  HTML/CSS – JavaScript - JSON Browser View ViewModel Model HTML & CSS JavaScript JSON <h1> var x; {a: b }
  • 13. Javascript Library to simplify dynamic UIs with automatic refresh.  Core Concepts  Declarative Bindings  Dependency Tracking  Templates  Extensible
  • 14. If using ASP.NET MVC  NuGet Package Manager  Download  knockoutjs  jQuery
  • 15. Observable  Computed Observable  Observable Arrays  Declarative bindings  Template Support
  • 16. Create the Model  Retrieve Data: usually via Ajax or other form data retrieval (API, LocalStorage).  Create the ViewModel  Encapsulate UI behavior and data from model.  Create the View (HTML Markup)  <label data-bind=“text: name” />  Bind the ViewModel to the view  applyBindings(viewModel)
  • 17. var viewModel = { firstName: ko.observable("John"), lastName: ko.observable("Doe") }; ko.applyBindings(viewModel); First Name: <input type="text“ data-bind="value: firstName"/> Last Name: <input type="text" data-bind=“value: lastName" /> <span data-bind="text : firstName"></span> <input type="text" data-bind="value : lastName" />
  • 18. var vm = { quantity: ko.observable(10), price: ko.observable(100), taxRate: ko.observable(8.75) }; viewModel = new vm(); viewModel.totalCost = ko.computed(function () { return (parseInt("0" + this.quantity(), 10) * this.price()) * this.taxRate(); }, viewModel); ko.applyBindings(viewModel);
  • 19. var viewModel = { States: ko.observableArray([ { State: "New York", Cities: ['New York City', 'East Hampton', 'Yonkers'] }, { State: "New Jersey", Cities: ['Jersey City', 'Hoboken', 'Maplewood'] }, { State: "Connecticut", Cities: ['Stamford', 'Greenwich'] }, { State: "Pennsylvania", Cities: ['Philadelphia'] }, ]), selectedState: ko.observable(), selectedCity: ko.observable() }; viewModel.selectionMade = ko.computed(function () { return (this.selectedState() && this.selectedCity()); }, viewModel); ko.applyBindings(viewModel);
  • 20. Type Description visible Used to hide or show DOM elements text Display text value in a DOM element html Display html in a DOM element css Add or remove CSS classes from DOM elements style Apply specific style to a DOM Element attr Set the value of any attribute on a DOM element
  • 21. binding Description foreach Used for rendering lists based on array bindings. If Conditional inclusion of markup and any related binding based on truthy condition Ifnot Conditional inclusion of markup and any related binding based on a falsey condition with Creates a new binding context changing what descendent element bind to.
  • 22. binding Description click Add an event handler so a function is invoked when the associated DOM element is clicked. event Add an event handler than can be bound to any event, such as keypress, mouseover or mouseout. submit Event handler used when submitting forms. enable Used to enable DOM elements only when the parameter value is true. Typically used with form elements like input, select, and textarea. disable Opposite of enable. Used in the same way.
  • 23. binding Description value Associates a DOM’s element value with a propery on the viewmodel. hasfocus Two way binding for setting focus on an element and chekcing whether an element has focus. checked This binding is used for checkable controls. Radio button or checkbox. options Used to bind the elements of a drop-down list or multi-select list. selectedOptions Bind to elements that are currently selected. Used with select and options bindings. uniqueName Gives an element a unique name if it does not already have a name attribute.
  • 24. // Subscribe myViewModel.totalCost.subscribe(function(newValue) { alert(“Let’s check if we are above our budget" + newValue); }); // Dispose of subscription var subscriptionCost = myViewModel.totalCost.subscribe(function(newValue) { /* do some work */ }); // ...then later... subscriptionCost.dispose();
  • 25. Custom Bindings  Plugins  TodoMVC  http://addyosmani.github.com/todomvc/  Knockbackjs  http://kmalakoff.github.com/knockback/  KnockoutMVC  http://knockoutmvc.com/
  • 26. Named Templates  Anonymous Templates  Inline  External
  • 27. Register a binding by adding it as a subproperty of ko.bindingHandlers.  Need to supply two functions:  init  update  And then use it with DOM element bindings. <div data-bind=“customBindingName: someValue"> </div>
  • 28. ko.bindingHandlers.customBindingName = { init: function (element, valueAccessor, allBindingsAccessor, viewModel) { // This will be called when the binding is first applied to an element // Set up any initial state, event handlers, etc. here }, update: function (element, valueAccessor, allBindingsAccessor, VM) { // This will be called once when the binding is first // applied to an element, and again whenever the associated // observable changes value. // Update the DOM element based on the supplied values here. } };
  • 29. Main Site (Steve Sanderson - Author)  http://knockoutjs.com  Ryan Niemeyer - Contributor  http://www.knockmeout.com
  • 30. Contact:  http://blog.boulosdib.com  @boulosdib