Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用新对象更新数组_Angular_Ionic2 - Fatal编程技术网

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的简单示例,希望对你有所帮助