Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an ionic 5 app to be build for browser. I have installed @ionic/Storage, etc. I have a function in my service the current iteration is as follows:

async setStorageObj( key: string, values: any) {
console.log(key, values);
return this.storageCtrl.set( key, values );

}

"key" is a single string "product attributes" and values is an object of arrays(I think). It looks like this in the developer console: Product Attributes: [sportsdemo_x_xxx: [{key:value pairs}, {key:value pairs}, {key:value pairs}], sportsdemo_y_yyyyy: [{key:value pairs}, {key:value pairs}], ...etc]

The console log above shows correct in the console so I know the values are there. However the its showing up in storage as "ProductAttributes: []. I am simply unable to figure out the correct syntax. I've been at it for a awhile and its late... maybe I am just tired. Your help would be appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

I came up with two solution to this question:

  1. loop through the object of arrays and set each array

    for (k in object) { 
       this.storageCtrl.set (k, object(k)); }
    

or

  1. the solution I went with:

    async setStorageObj( values: any[]) {
        return await this.storageCtrl.set("productAttributes", JSON.stringify(values));
    }
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...