I'm working on an add-on with the Firefox SDK. In the addon I store an associative array with simple-storage.
Associative array I store with simple prefs
var spammer = [];
spammer['id'] = res[0];
spammer['username'] = res[1];
spammer['date'] = res[2];
ss.storage.spammers.push(spammer);
console.log(ss.storage.spammers[i]['id']);
console.log(ss.storage.spammers[i]['username']);
console.log(ss.storage.spammers[i]['date']);
This seems to work, while the add-on is active the right values are logged.
However when I the browser the following code is run
require("sdk/tabs").on("ready", function(tab) {
for (i = 0; i < ss.storage.spammers.length; i++) {
console.log(ss.storage.spammers[i]['id']);
console.log(ss.storage.spammers[i]['username']);
console.log(ss.storage.spammers[i]['date']);
}
});
But now when I run the code is run 'undefined' values are logged
(the first 3 lines are from previous session stored with simple-prefs, the 3 working lines are from the new session)
Is it not possible to store associative arrays with simple-storage or is something else the matter?
In
var spammer = [];
spammer['id'] = res[0];
spammer['username'] = res[1];
spammer['date'] = res[2];
ss.storage.spammers.push(spammer);
console.log(ss.storage.spammers[i]['id']);
console.log(ss.storage.spammers[i]['username']);
console.log(ss.storage.spammers[i]['date']);
Change var spammer = [];
to var spammer = {};