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 MODELBasketCheeseSubtotalTotal:$I’ll step through each category of change that I made and explain the effect it has. As I do this, pleasereflect on how little has to change to add this feature. Once again, a view model and some basicapplication structure create a foundation to which new features can be quickly and easily added.Extending the View ModelThe change to the view model in this listing is the addition of the total property, which is a computedobservable that sums the individual subtotal values:cheeseModel.total = ko.computed(function() {var total = 0;map<strong>Pro</strong>ducts(function(elem) {total += elem.subtotal();});return total;});69www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!