Storing and retrieving a KO ObservableArray from a HashTable

I have an observable array that I am contacting with my aspx:

var contacts = ko.observableArray(),

When this fills up, I store the array in a hash table, so I don’t need to retrieve the value from my service again (this is a very slow process, so if I don’t want to retrieve something, you already received it earlier):

var toHash = contacts();
contactsHash[query] = toHash;

My hash table:

var contactsHash = {},

Here's what my observable array looks like when it is stored (key is string):

toHash

Here's how I pulled it out:

if (contactsHash[query]) {
     contacts.removeAll();
     var retrieved = contactsHash[query];
     contacts(retrieved);
}

And this is what it looks like when I pull it out:

enter image description here

This, obviously, causes me problems, since the observed array is not filled with the array that I previously stored ... So something worked between them, I am absolutely sure that they use the key that I store and receive using same thing. Can someone point out what is wrong here?

+3
2

JavaScript . contacts.removeAll();, contactsHash[query], .


contactsHash[query] = toHash.slice();

contactsHash[query] = toHash;

:
slice() .

+3

- , JavaScript. .

+3

All Articles