Can you please tell me why this does not work.
HERE'S THE OBJECT
// Holds User selected fields & filter values
App.service('userFilters', function () {
var store = {};
this.toArray = function () {
var records = [];
return Object.keys(store).map(function (key) {
records.push([key, store[key]]);
});
};
this.get = function (key) {
return store[key];
};
this.set = function (key, value) {
store[key] = value;
};
});
// HERE'S THE CODE TO USE IT
userFilters.set('DD','XX');
userFilters.set('a', 'b');
userFilters.set('c', 'bdddddd');
// gET THE DATA
var uFilters = userFilters.toArray();
if (uFilters.length > 0) {
for (p = 0; p < uFilters.length; p++) {
var x = uFilters[p];
}
}
Lets see, when you set the value you're passing a key and a value.
When you're accessing what are you trying to achieve?
The closest thing I can think here if to add a method in the factory that gives you all the items so that you can loop through them. Something like:
Open in new window
This will give you a collection of objects that you can use in your loop as:Open in new window
But it's a mess because you don't know what's inside each object item...That's why I don't understand what's your goal inside the loop.