SlideShare a Scribd company logo
www.dotnet.lv
Valdis Iljuconoks
Software Architect
Microsoft MVP

Geta Latvia, Viiar Consulting
valdis.iljuconoks@dotnet.lv
http://dotnet.lv/blogs/vi
knockout.js
$(function () {
    $("#btn").click(function () {
        $.getJSON("/api/customers").then(function (customers) {
            $.each(customers, function () {
                $("<li>").text(this.FirstName + " " +
this.LastName).appendTo("#customers");
            });
        });
    });
});
$(function () {
    $("#btn").click(function () {
        $.getJSON("/api/customers").then(function (customers) {
            var html = tmpl("cust_tmpl", { customers: customers });
            $("#customers").html(html);
        });
    });
});




<script type="text/html" id="cust_tmpl">
  {{each customers}}
    <li><a href="/api/customer/${Id}">${FirstName}
${LastName}</a></li>
  {{/each}}
</script>
Observables
  Bindings
  Utilities
Data features
  Plug-ins
Observables
Observable
        Observable Array
Dependent Observables (Computed)
// read value
var val = viewmodel.name();

// set value
viewmodel.name(“Valdis”)




                      Observables
   Functions (not all browsers support getters and setters)
viewmodel.customers = ko.obserableArray();

viewmodel.customers.push(new customer());




                 Observable Array
                     Use with collections
             Detect changes only within an array
         Use knockout array methods (cross-browser)
indexOf(item)
   slice(2, 4)
   push(item)
      pop()
 unshift(item)
      shift()
    reverse()
      sort()
remove(item)
  removeAll()
viewmodel.fullname = ko.computed(function() {
    return this.name() + “ ” + this.surname();
})




      Dependent Observables (Computed)
            “this” keyword has to be managed
Observables
  Bindings
  Utilities
Data features
  Plug-ins
Bindings
Built-in Bindings
Custom bindings
Built-in Bindings
data-bind=“”

   value:
   html:
    text:
     css:
   style:
  visible:
 template:
      …
Control-flow bindings
data-bind=“”

  foreach:
     if:
   ifnot:
    with:
     …
Custom bindings
(most powerful extension point)
Event binding
addOnEnter: function(model, event) {
    var keycode = (event.which ? event.which :
event.keyCode);
    if (keycode === 13) {
        viewModel.addTCustomer();
    }

    return true;
}



data-bind=“event: {keypress: addOnEnter}”
ko.bindingHandlers.yourBindingName = {
  init:
  update:
}




              Custom bindings
             Define your own behavior
ko.bindingHandlers.executeOnEnter = {
    init:
function(element, valueAccessor, allBindingAccessor, viewModel) {
    var value = valueAccessor();
    $(element).keypress(function(event) {
        var keycode = (event.which ? event.which : event.keyCode);
        if (keycode === 13) {
            value.call(viewModel);
            return false;
        }

         return true;
         });
     }
};



data-bind=“executeOnEnter: addCustomer”
Observables
  Bindings
  Utilities
Data features
  Plug-ins
Utilities
ko.utils.arrayFilter()
ko.utils.arrayFilter()
     ko.utils.arrayFirst()
   ko.utils.arrayForEach()
   ko.utils.arrayIndexOf()
     ko.utils.arrayMap()
  ko.utils.compareArrays()
ko.utils.unwrapObservable()
               …
Observables
  Bindings
  Utilities
Data features
  Plug-ins
Data features
ko.toJS()
ko.toJSON()
Observables
  Bindings
  Utilities
Data features
  Plug-ins
Plug-ins
ko.mapping.*
Observables
  Bindings
  Utilities
Data features
  Plug-ins
Resources
knockoutjs.com
    blog.stevensanderson.com
         knockmeout.com
stackoverflow.com -> “knockoutjs”
groups.google.com -> “knockoutjs”
must have to build interactive UI
?
Valdis Iljuconoks
Software Architect
Microsoft MVP

Geta Latvia, Viiar Consulting
valdis.iljuconoks@dotnet.lv
http://dotnet.lv/blogs/vi
www.dotnet.lv

More Related Content

PDF
jQuery secrets
Bastian Feder
 
PPTX
AngularJS $Provide Service
Eyal Vardi
 
PPT
Backbone.js
Knoldus Inc.
 
PPTX
AngularJS - $http & $resource Services
Eyal Vardi
 
PDF
jQuery and Rails, Sitting in a Tree
adamlogic
 
PPTX
Big Data for each one of us
OSCON Byrum
 
PPTX
Optimizing Angular Performance in Enterprise Single Page Apps
Morgan Stone
 
PPTX
Pengenalan blaast platform sdk
Arief Bayu Purwanto
 
jQuery secrets
Bastian Feder
 
AngularJS $Provide Service
Eyal Vardi
 
Backbone.js
Knoldus Inc.
 
AngularJS - $http & $resource Services
Eyal Vardi
 
jQuery and Rails, Sitting in a Tree
adamlogic
 
Big Data for each one of us
OSCON Byrum
 
Optimizing Angular Performance in Enterprise Single Page Apps
Morgan Stone
 
Pengenalan blaast platform sdk
Arief Bayu Purwanto
 

What's hot (20)

PPTX
AngularJS Compile Process
Eyal Vardi
 
KEY
Special Events
Brandon Aaron
 
PPTX
jQuery Foot-Gun Features
dmethvin
 
PPTX
AngularJS Routing
Eyal Vardi
 
PPTX
AngularJS Services
Eyal Vardi
 
PDF
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
PPTX
Taming that client side mess with Backbone.js
Jarod Ferguson
 
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
Robert Nyman
 
PPT
Backbone js
husnara mohammad
 
KEY
Special Events: Beyond Custom Events
Brandon Aaron
 
PPTX
Building an End-to-End AngularJS Application
Dan Wahlin
 
PDF
Before there was Hoop Dreams, there was McDonald's: Strange and Beautiful
chicagonewsonlineradio
 
PDF
Backbone Basics with Examples
Sergey Bolshchikov
 
PDF
jQuery
Andrew Homeyer
 
KEY
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
Ben Teese
 
PPTX
Nodejs do teste de unidade ao de integração
Vinícius Pretto da Silva
 
PPTX
Angular 2.0 forms
Eyal Vardi
 
PDF
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
Robert Nyman
 
PDF
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
Robert Nyman
 
KEY
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Vagmi Mudumbai
 
AngularJS Compile Process
Eyal Vardi
 
Special Events
Brandon Aaron
 
jQuery Foot-Gun Features
dmethvin
 
AngularJS Routing
Eyal Vardi
 
AngularJS Services
Eyal Vardi
 
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Taming that client side mess with Backbone.js
Jarod Ferguson
 
JavaScript APIs - The Web is the Platform - MDN Hack Day - Buenos Aires
Robert Nyman
 
Backbone js
husnara mohammad
 
Special Events: Beyond Custom Events
Brandon Aaron
 
Building an End-to-End AngularJS Application
Dan Wahlin
 
Before there was Hoop Dreams, there was McDonald's: Strange and Beautiful
chicagonewsonlineradio
 
Backbone Basics with Examples
Sergey Bolshchikov
 
The Return of JavaScript: 3 Open-Source Projects that are driving JavaScript'...
Ben Teese
 
Nodejs do teste de unidade ao de integração
Vinícius Pretto da Silva
 
Angular 2.0 forms
Eyal Vardi
 
JavaScript APIs - The Web is the Platform - MozCamp, Buenos Aires
Robert Nyman
 
JavaScript APIs - The Web is the Platform - MDN Hack Day, Santiago, Chile
Robert Nyman
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Vagmi Mudumbai
 
Ad

Viewers also liked (8)

PPS
HONEYMOON IN VENICE(mandolin) Mézeshetek Velencében
DIO GYULA
 
PPS
INDIAN LOVE CALL Indián szerelmi dal
DIO GYULA
 
PPTX
CSharp 5 Async
Valdis Iljuconoks
 
PPTX
Client side development with knockout.js
Valdis Iljuconoks
 
PPTX
Loving data with F#
Valdis Iljuconoks
 
PPTX
Lap around Visual Studio 2013
Valdis Iljuconoks
 
PPTX
Parallel Development in VS10
Valdis Iljuconoks
 
PPTX
Parallel development in VS 2012
Valdis Iljuconoks
 
HONEYMOON IN VENICE(mandolin) Mézeshetek Velencében
DIO GYULA
 
INDIAN LOVE CALL Indián szerelmi dal
DIO GYULA
 
CSharp 5 Async
Valdis Iljuconoks
 
Client side development with knockout.js
Valdis Iljuconoks
 
Loving data with F#
Valdis Iljuconoks
 
Lap around Visual Studio 2013
Valdis Iljuconoks
 
Parallel Development in VS10
Valdis Iljuconoks
 
Parallel development in VS 2012
Valdis Iljuconoks
 
Ad

Similar to Knockoutjs UG meeting presentation (20)

PDF
jQuery
Ivano Malavolta
 
PDF
jQuery Rescue Adventure
Allegient
 
PDF
Understanding backbonejs
Nick Lee
 
PPT
JQuery Flot
Arshavski Alexander
 
PDF
The rise and fall of a techno DJ, plus more new reviews and notable screenings
chicagonewsyesterday
 
KEY
Scala on Your Phone
Michael Galpin
 
PDF
mobl presentation @ IHomer
zefhemel
 
PDF
Aplicacoes dinamicas Rails com Backbone
Rafael Felix da Silva
 
PDF
Clean Javascript
Ryunosuke SATO
 
PDF
mobl
zefhemel
 
PDF
Game jump: frontend introduction #1
Sebastian Pożoga
 
PPT
Kick start with j query
Md. Ziaul Haq
 
PPT
Backbone js
Knoldus Inc.
 
ODP
JQuery introduction
Pradeep Saraswathi
 
PDF
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
PDF
How te bring common UI patterns to ADF
Getting value from IoT, Integration and Data Analytics
 
PDF
Discontinuing Reader Matches
chicagonewsonlineradio
 
PDF
ScalikeJDBC Tutorial for Beginners
Kazuhiro Sera
 
KEY
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
PPTX
Javascript first-class citizenery
toddbr
 
jQuery Rescue Adventure
Allegient
 
Understanding backbonejs
Nick Lee
 
JQuery Flot
Arshavski Alexander
 
The rise and fall of a techno DJ, plus more new reviews and notable screenings
chicagonewsyesterday
 
Scala on Your Phone
Michael Galpin
 
mobl presentation @ IHomer
zefhemel
 
Aplicacoes dinamicas Rails com Backbone
Rafael Felix da Silva
 
Clean Javascript
Ryunosuke SATO
 
mobl
zefhemel
 
Game jump: frontend introduction #1
Sebastian Pożoga
 
Kick start with j query
Md. Ziaul Haq
 
Backbone js
Knoldus Inc.
 
JQuery introduction
Pradeep Saraswathi
 
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
How te bring common UI patterns to ADF
Getting value from IoT, Integration and Data Analytics
 
Discontinuing Reader Matches
chicagonewsonlineradio
 
ScalikeJDBC Tutorial for Beginners
Kazuhiro Sera
 
jQuery: Tips, tricks and hints for better development and Performance
Jonas De Smet
 
Javascript first-class citizenery
toddbr
 

Recently uploaded (20)

PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
The Future of Artificial Intelligence (AI)
Mukul
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 

Knockoutjs UG meeting presentation