Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
KnockoutJS Web Development

You're reading from   KnockoutJS Web Development Efficiently work with data, web templates, and custom HTML tags using KnockoutJS

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781782161028
Length 178 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
John Farrar John Farrar
Author Profile Icon John Farrar
John Farrar
Arrow right icon
View More author details
Toc

Mapping options


There are times when you are loading data into a page application that doesn't need to be changed. This is just static data and making it observable spends extra processor time and memory resources for no gain. When passing data into the mapping handler, you can set which items are mapped as observable items, using the following lines of code:

var data = {
  a: "a",
  b: [{ b1: "v1" }, { b2: "v2" }],
  c: true
};
var result = ko.mapping.fromJS(data, { observe: "a" });
var result2 = ko.mapping.fromJS(data, { observe: "a", copy: "b" }); //will be faster to map.

The results we get from the result and result2 variables will be the same. Why? This is because when we declare the observe items the other items are assumed to be copied items. If a single item is passed in we can declare it outside an array, as we did with a. If multiple items are passed in we would declare them in an array, as ["a","c"]. This would make both a and c observable items.

If we just wanted to declare an item...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image