簡體   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