Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'];
like image 523
MichaelS Avatar asked Oct 22 '22 05:10

MichaelS


1 Answers

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.

like image 173
MichaelS Avatar answered Oct 26 '22 21:10

MichaelS