admin管理员组

文章数量:1419225

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'];

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'];
Share Improve this question asked Oct 21, 2012 at 11:21 MichaelSMichaelS 7,14310 gold badges53 silver badges75 bronze badges 2
  • Have you checked out this guy's dictionary implementation? github./jamesfoster/knockout.observableDictionary – Tom W Hall Commented Oct 21, 2012 at 11:34
  • @TomHall: Thanks for the link, it looks good. I've found another more naive implementation: wiredprairie.us/blog/index.php/archives/1563 – MichaelS Commented Oct 21, 2012 at 11:37
Add a ment  | 

1 Answer 1

Reset to default 3

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.

本文标签: javascriptIs there a way to use koobservableArray as mapStack Overflow