2017-11-06 3 views
0

イオンネイティブSMSパッケージで使用する電話番号の配列を作成しようとしています。Ionic - 可変キーを使用してオブジェクトをプッシュできません

let array; 
let promises_array = []; 
    this.storage.get('username').then((val) => { 
    console.log('in storage'); 
    this.follow = this.af.list('/profiles/stylists/' + val + "/followers"); 
    this.subscription = this.follow.subscribe(items => items.forEach(item => { 
     promises_array.push(new Promise((resolve, reject) => { 
     console.log(JSON.stringify(item) + " item item item"); 
     let arr = Object.keys(item); 
     console.log(item[arr[0]] + " type followers"); 
     array.push(item[arr[0]]); ; 
     resolve(); 
     })) 
    })); 

    Promise.all(promises_array).then(() => { 
     let month1 = date.getUTCMonth; 
     let date1 = date.getUTCDate; 


     this.sms.send(array, val + " just opened up a spot at " + time + " on " + month1 + " " + date1 + "!") 
      .catch(e => { console.log(JSON.stringify(e))}); 
    }) 
    boool = false; 
}) 

私が取得エラー(それはアプリで表示される実行時エラーです) -

Uncaught (in promise): TypeError undefined is not an object (evaluating 'array_1.push') 

私はarray_1.pushがラインに対応していることが確認されています:それはかなり単純なコードです

array.push(item[arr[0]]);

item[arr[0]]が定義されていないと言っているが、コンソール出力は次のようになります。

[10:54:49] console.log: in storage 
[10:54:49] console.log: {"V":"7818646634"} item item item 
[10:54:49] console.log: 7818646634 type followers 
[10:54:52] console.log: "Message cancelled." 

三行目は、それがそれをプッシュする行くとき、それはちょうどその未定義を考えて、item[arr[0]]が何であるかを認識することを示しています。どんな助けも素晴らしいだろう、ありがとう。

答えて

1

array変数を配列として定義していないため、プッシュできることがわかりません。

let array;

あなたが行う必要があります。

let array = [];

+0

を...ハハ、このような愚かな監督を... – ewizard

+1

我々はすべてそこにしてきたおかげで:) – iamalismith

関連する問題