-1

everyone.

I've got a chrome.storage.local.get function that is supposed to accept objects that have already been set up to the local memory. It's structured something like...

let numberOfRows = 3; //The number of generic rows of this information I'll need
let storageIDs = []; //The keys for the object that I'll need.
let storageArray = storageIDs.slice(0); //The default keys I need I'll number if I need to
let storageObject = {}; //The final object will be stored in here

for(...) {//Fill the storageArray with each key (number appended) at the end}

for(...) {//Turn each finalized key into an object stored in an storageObject}

chrome.storage.local.get({
    (function(){
      for(let index in storageObject) { 
          if (storageObject.hasOwnProperty(index)) {
            return storageObject[index];
          }
        }
    })()
}, function (result) {...}

So... The end result is that I'll set the number of rows and pass in an array of keys, and then it'll turn each of those into an object reference to the chrome local storage.

But I don't want to call storage.local.get more than once, so I'm wondering if it's possible to return each object inside of storageObject inside of the argument list? Or is there a simpler way to get all of the objects inside of storageObject passed in as arguments?

Edit: chrome.storage.local.get is expecting a set of objects, "keyValue1": {}, "keyValue2": {} and so on.

When it passes those objects into result, I can call them back as result["keyValue1"], but if I put in my object that has all of the keys in it, I can only call back that object.

What I need is a way to dynamically pass in all of the properties of storageObject without calling chrome.storage.local.get() more than once.

Junior Dev
  • 114
  • 10
  • 1
    Your question is not clear? What is the expected output, format? – Pankaj Shukla May 15 '17 at 19:11
  • What parameter does `chrome.storage.local.get` expect? A single plain object? – guest271314 May 15 '17 at 19:16
  • Possible duplicate of [Can we set persistent default parameters which remain set until explicitly changed?](http://stackoverflow.com/questions/43466657/can-we-set-persistent-default-parameters-which-remain-set-until-explicitly-chang) – guest271314 May 15 '17 at 19:19
  • Clarified what `chrome.storage.local.get` expects and what I'm hoping for. None of the answers in that question seems to answer mine. They all seem to be a preset list of parameters and declaring the value of each one. I'm looking for passing in an unknown amount of parameters as individual objects from an object or array. – Junior Dev May 15 '17 at 19:38
  • At first glance the goal seems a needless complication. Seeing an example of the desired code would be helpful for me. So far it seems easily doable via ES2015 `...` spread operator or its polyfill. – wOxxOm May 15 '17 at 21:29
  • Turns out I'm an idiot and this is a needless complication. The entire time I could have solved everything by removing the curly brackets in the `get` call and passing in the `storageArray`, which would be treated like an array of object keys, which was exactly what I needed. – Junior Dev May 15 '17 at 22:41

1 Answers1

0

My requirement was to pass in a dynamic amount of arguments into the chrome.storage.local.get function that would each be treated as an object, and those objects would all be picked up as the result of the enclosed function.

Turns out I could do that all along.

let numberOfRows = 3; //The number of generic rows of this information I'll need
let storageIDs = []; //The keys for the object that I'll need.
let storageArray = storageIDs.slice(0); //The default keys I need I'll number if I need to

for(...) {//Fill the storageArray with each key (number appended) at the end}

chrome.storage.local.get( storageArray, function (result) {...})

get accepts an object (the curly braces) or an array of object keys. I never got it to work because I kept forget to remove the curly braces.

Junior Dev
  • 114
  • 10