简体   繁体   中英

Ionic storage is returning expected array as a string

I'm storing ID's in the storage.

See example: 在此处输入图像描述

I store the storage to a local string [];

The problem is when I try to push new ids to storage.

 addIdToDontShowList(id: string): Promise<any> { return this.storage.get(DONT_SHOW).then((ids: string[]) => { if (ids) { console.log('ids', ids); ids.push(id); return this.storage.set(DONT_SHOW, ids); } else { return this.storage.set(DONT_SHOW, id); } }); }

I get an error that the method push does not exist on IDs.

ERROR Error: Uncaught (in promise): TypeError: ids.push is not a function TypeError: ids.push is not a function

How do I convert ids to a string [] so that I can push new items to ids before setting the storage again?

I fixed this by making my initial commit to storage and array.

Instead of return this.storage.set(DONT_SHOW, id); I stored the id into and array and set it using the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM