12.07.2015 Views

Pro JavaScript for Web Apps pdf - EBook Free Download

Pro JavaScript for Web Apps pdf - EBook Free Download

Pro JavaScript for Web Apps pdf - EBook Free Download

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 3 ADDING A VIEW MODELCreating a View ModelThe next step is to define some data, which will be the foundation of the view model. To get started, Ihave added an object that describes the products in the cheese shop, as shown in Listing 3-2.Listing 3-2. Adding Data to the Documentvar cheeseModel = {category: "French Cheese",items: [ {id: "camembert", name: "Camembert", price: 18},{id: "tomme", name: "Tomme de Savoie", price: 19},{id: "morbier", name: "Morbier", price: 9}]};$(document).ready(function() {$('#buttonDiv input:submit').button().css("font-family", "Yanone");});I have created an object that contains details of the cheese products and assigned it to a variablecalled cheeseModel. The object describes the same products that I used Chapter 2 and is the foundationof my view model, which I will build throughout the chapter; it is a simple data object now, but I’ll bedoing a lot more with it soon.• Tip If you find yourself staring at the blinking cursor with no real idea how to define your application data, thenmy advice is simple: just start typing. One of the biggest benefits of embracing a view model is that it makeschanges easier, and that includes changes to the structure of the underlying data. Don’t worry if you don’t get itright, because you can always correct it later.48www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!