简体   繁体   English

有没有办法使用ko.observableArray作为地图?

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

Is there a way to use an ko.observableArray like a map/dictionary? 有没有办法像地图/字典一样使用ko.observableArray

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

Found two possible implementations: 找到两种可能的实现:

  1. James Foster / knockout.observableDictionary - It has everything a dictionary needs. James Foster / knockout.observableDictionary - 它拥有字典所需的一切。 (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. 我最终使用了observableDictionary,它快速而简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM