Bonjour,
Je cherche à faire un service angular pour stocker des données.
Mon idée est d'utiliser un tableau de tableau associatif et de récupérer ces valeurs via la clé.
Voici mon code :
Sauf que ma récupération ne fonctionne pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 .factory('storeService', function(){ // create empty function storeService(){ this.store = []; } // use this to register new store from a controller, other factory, wherever. storeService.prototype.addStore = function(st){ this.store.push(st); } // find value storeService.prototype.findById = function(id){ // for all item in the table for(var ind in this.store){ // check if the item has the key requested if(this.store[ind].hasOwnProperty(id)) { console.log('us ', this.store[ind][id]); return this.store[ind][id]; } } return null; } return new storeService(); })
Voici la forme de mon objet :
Une idée du problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part this.store = [{id: 'user1', 'value': { 'id': '11060', 'username': "jctoto", 'email': "jctoto@toto.net"}}];
Merci.
Partager