2013-11-29 40 views
3

我得到我的$資源GETALL()作爲

[$promise: Object, $resolved: false] 
0: Resource 
1: Resource 
$promise: Object 
$resolved: true 
length: 2 
__proto__: Array[0] 

和我使用的是服務數據對象其保存爲

this.datas = []; 
this.nestedData = []; 
this.setdata = function(datas) { 
    this.datas = datas; 
    console.log(this.datas); // get data as mentioned above 
    console.log(this.datas.length); // here i get length as 0 
    for(var i=0;i < datas.length; i++) { 
     this.nestedData.push(datas[i].nested); 
    } 
}; 

爲什麼我的長度爲0?如何解決這個問題?

回答

0

我認爲你正在使用相同的名稱,如DATAS

this.datas = [];//Or use this.datas = {}; 
this.nestedData = []; 
this.setdata = function(data) {//Changed name datas to data 
    this.datas = data; 
    console.log(this.datas); 
    console.log(this.datas.length); 
    for(var i=0;i < datas.length; i++) { 
     this.nestedData.push(datas[i].nested); 
    } 
};