Indexer accepts arbitrary key to index by. Fix bug: Return an object instead of an array.

This commit is contained in:
Rohan Mitchell
2014-11-27 11:34:35 +11:00
parent 47b479c6c9
commit 8baed4429c
2 changed files with 12 additions and 3 deletions

View File

@@ -6,8 +6,8 @@
angular.module("ofn.admin").factory 'Indexer', ->
new class Indexer
index: (data) ->
index = []
index: (data, key='id') ->
index = {}
for e in data
index[e.id] = e
index[e[key]] = e
index