繁体   English   中英

离子存储将预期的数组作为字符串返回

[英]Ionic storage is returning expected array as a string

我将 ID 存储在存储器中。

参见示例: 在此处输入图像描述

我将存储存储到本地字符串[];

问题是当我尝试将新 ID 推送到存储时。

 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); } }); }

我收到一个错误消息,指出 ID 上不存在推送方法。

错误错误:未捕获(承诺):类型错误:ids.push 不是函数类型错误:ids.push 不是函数

如何将 ids 转换为字符串 [] 以便我可以在再次设置存储之前将新项目推送到 ids?

我通过对存储和阵列进行初始提交来解决此问题。

而不是返回 this.storage.set(DONT_SHOW, id); 我将 id 存储到数组中并使用数组进行设置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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