Angular 使用新对象更新数组
我有一个对象,每当发生数据更改时,它都会被更新,我需要将以前的数据和更新的数据存储到一个数组中,并在需要时检索它Angular 使用新对象更新数组,angular,ionic2,Angular,Ionic2,我有一个对象,每当发生数据更改时,它都会被更新,我需要将以前的数据和更新的数据存储到一个数组中,并在需要时检索它 /* currently i could get 1 data i need multiple data stored to a storage as array*/ get(){ this.storage.get('uploaded').then((data) => { console.log("get data", JSON.
/* currently i could get 1 data i need multiple data stored to a storage as array*/
get(){
this.storage.get('uploaded').then((data) => {
console.log("get data", JSON.parse(data));
});
}
set(){
var obj = { upload: true,
file: file.audio //this will hold an object which vary when required
}
this.storage.set('uploaded', JSON.stringify( obj ));
}
您可以使用数组的push()方法用新数据更新数组
var obj = new Array();
obj.push();// use this whenever you have new data
并使用它来访问这些值
for (var i in obj) {
//access values using obj[i]
}
文件是对象的数组吗?我想你需要做任何一个文件数组,如果你需要有多个值,你需要做一个推送。如果文件是一个对象,你能给我创建一个样本吗?你有一个@rahul的简单示例,希望对你有所帮助