Top Banner
KnockoutJS Introduction Prepared by : Balakrishnan
19
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Knock out Introduction with samples (jsfiddle.net)

KnockoutJS Introduction

Prepared by : Balakrishnan

Page 2: Knock out Introduction with samples (jsfiddle.net)

KnockoutJS Introduction

• Client-Side MVVM JavaScript Library

• 40kb (minified), 166kb (debug)

• No dependencies

• Works on all mainstream browsers

IE6+, FF2+, Chrome, Safari, Opera

• Developed with BDD

• NuGet or knockoutjs.com

Page 3: Knock out Introduction with samples (jsfiddle.net)

MVVM Pattern

MODEL

VIEW MODEL

VIEW

Page 4: Knock out Introduction with samples (jsfiddle.net)

Knockout Features

Dependency Tracking

Automatic UI Refresh

Declarative Bindings

Templating

Page 5: Knock out Introduction with samples (jsfiddle.net)
Page 6: Knock out Introduction with samples (jsfiddle.net)
Page 7: Knock out Introduction with samples (jsfiddle.net)
Page 8: Knock out Introduction with samples (jsfiddle.net)
Page 9: Knock out Introduction with samples (jsfiddle.net)

Demo - 1

• Basic Example

• data-bind attribute

• ko.observable()

• Ko.observableArray()

• ko.applyBindings()

• Demo

• Basics jsFiffle.net/BalaIn

• Dropdown

Page 10: Knock out Introduction with samples (jsfiddle.net)

Demo - 2

• Basic Example• Built In bindings

• Click

• Visible

• Css

• Value

• Text

• Style

• hasFocus

• Submit

• Demo• Submit

• hasFocus

Page 11: Knock out Introduction with samples (jsfiddle.net)

Demo - 3

• Custom Binding

• Template

• Demo

• http://jsfiddle.net/balain/nu91g603/

• http://jsfiddle.net/balain/nu91g603/3/

• http://jsfiddle.net/balain/nu91g603/2/

Page 12: Knock out Introduction with samples (jsfiddle.net)

Demo - 4

• Some basic mapping (without mapping plugin)• ko.utils.arrayMap()

• Mapping (without mapping plugin)• Ko.utils.parseJson()

• Save data• Ko.toJSON(viewModel)

• Demo• http://jsfiddle.net/ybo0zrwh/

• http://jsfiddle.net/balain/berthw4c/

• http://jsfiddle.net/rniemeyer/vdcUA/

• http://www.knockmeout.net/2011/04/utility-functions-in-knockoutjs.html

Page 13: Knock out Introduction with samples (jsfiddle.net)

Demo - 5

• Binding Contexts

$root

$parent

$parents

$parents[0] == $parent

$parent[1] … $parent[n]

$data

Demo

http://jsfiddle.net/balain/nu91g603/6/

http://knockoutjs.com/documentation/binding-context.html

Page 14: Knock out Introduction with samples (jsfiddle.net)

Debugging Ko

Page 15: Knock out Introduction with samples (jsfiddle.net)
Page 16: Knock out Introduction with samples (jsfiddle.net)
Page 17: Knock out Introduction with samples (jsfiddle.net)

Why Knockout

• High level link between UI & data model

• Extensible

• Usable in existing apps/architecture

• Learning Resources

• Same MV* pattern & benefits as other solutions

Page 18: Knock out Introduction with samples (jsfiddle.net)

Resources

• knockoutjs.com

Live Examples/Tutorials

Documentation

• Knock Me Out - Ryan Niemeyer’s blog

• http://www.dotnet-tricks.com/Tutorial/knockout

• Debugging Ko

• jsFiddle

Page 19: Knock out Introduction with samples (jsfiddle.net)

Questions