Book Image

KNOCKOUTJS BLUEPRINTS

By : Carlo Russo
Book Image

KNOCKOUTJS BLUEPRINTS

By: Carlo Russo

Overview of this book

Table of Contents (12 chapters)
KnockoutJS Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting jQuery because it can be useful


In the previous section, we put the data directly inside the View Model; this was just to show how the ViewModel works. In any normal application the source of your data is online and you get it by calling a remote service.

Anyway, as you can see if you look at the documentation of KnockoutJS, the library doesn't provide you any help to take the data. We could use plain JavaScript to do this; but to make it a little easier, we will be using jQuery to deal with our AJAX request in the rest of the book.

Browser compatibility

One of the most relevant features of KnockoutJS is its browser compatibility; it even works on ancient browsers, so you can use it if you need to support them.

When you develop a big application to be used online you have to decide which browser you're going to support; the main reason is that each browser you decide to support means:

  • Testing on it

  • Checking if your code/style sheet/HTML page can be supported, and how

For this reason, many big companies keep an eye on the browser market share data; it helps you to decide if it's time to drop support for a particular browser.

I mentioned this here because we are going to use jQuery. This library is different from KnockoutJS, because you must choose between two branches: 1.x and 2.x.

The main difference here is the compatibility; if you want to support all the browsers KnockoutJS supports you have to download the 1.x branch, otherwise you can choose 2.x.

Note

For these chapters, we will use the 1.x branch (we will use 1.11.1). You can download the latest jQuery library here: http://code.jquery.com/jquery-1.11.1.min.js.

After you download it, save it as SimpleShowCase/js/jquery.js.

Then update the index page to include it before the row where we included KnockoutJS:

    </div>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/knockout.js"></script>