2012-10-21 81 views
5

有沒有像地圖/字典一樣使用ko.observableArray的方法?有沒有辦法使用ko.observableArray作爲地圖?

例如:

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

,然後使用鍵retrive值:

var value = arr['key']; 
+0

你看過這個人的字典實現嗎? https://github.com/jamesfoster/knockout.observableDictionary –

+0

@TomHall:感謝您的鏈接,它看起來不錯。 我發現了另一個更天真的實現: http://www.wiredprairie.us/blog/index.php/archives/1563 – MichaelS

回答

3

發現了兩個可能的實現:

  1. 詹姆斯·福斯特/ knockout.observableDictionary - 它擁有一切字典需求。 (感謝湯姆霍爾偉大的發現)
  2. A more naive implantation - 適合基本需求。

我結束了使用observableDictionary,它是快速和簡單的。

+1

我將for「knockout.observableDictionary」並將其轉換爲Bower包:https:/ /github.com/bennyn/knockout.observableDictionary - 因此它現在可以作爲Bower依賴檢索。 :) –

相關問題