我想在一个数组中推入多个项目,否则该项目将被覆盖。
所以我想我能做的是:
localForage.getItem("data", (err, results) => {
console.log('results', results)
// var dataArray = results ? results : [];
// data.push(results);
this.dataArray.push(results);
localForage.setItem("data", results);
console.log(localForage.getItem("data"));
})但这将替换最后一项,如何在该dataArray中推送多个localForage项?
发布于 2017-05-06 15:25:12
我刚刚用localForage测试了这一点,它是有效的:
假设var dataArray = with某些数据
1)如何用localForage中的内容替换现有的dataArray
localForage.getItem("data").then((results) => { dataArray = [].concat(results); });
2)如何将localForage中的数据添加到现有的dataArray中
localForage.getItem("data").then((results) => { dataArray = dataArray.concat(results); });
3)如何添加localForage中已有的内容
localForage.getItem("data").then((result) => {
dataArray = dataArray.concat(result);
localForage.removeItem("data");
localForage.setItem("data", dataArray);
});希望能有所帮助。
https://stackoverflow.com/questions/43793787
复制相似问题