MichaelS
MichaelS

Reputation: 7123

Is there a way to use ko.observableArray as map?

Is there a way to use an ko.observableArray like a map/dictionary?

For example:

var arr = ko.observableArray();
arr.push('key', { '.. Some object as value ..' });

And then retrive the value using the key:

var value = arr['key'];

Upvotes: 5

Views: 7035

Answers (1)

MichaelS
MichaelS

Reputation: 7123

Found two possible implementations:

  1. James Foster / knockout.observableDictionary - It has everything a dictionary needs. (Thanks to Tom Hall for the great find)
  2. A more naive implantation - suits the basic needs.

I ended up using the observableDictionary, it is fast and simple.

Upvotes: 3

Related Questions