簡體   English   中英

如何在 Angular 組件文件中獲取訂閱的 object 的索引?

[英]How to I get the index of a subscribed object in Angular component file?

this.arrName.subscribe(data, (index as i) => { //fake implementation
    let myData = data.inside[i].keyName;
}); 

我想實現這樣的東西。

你可以這樣做

this.arrName.subscribe(data => {
   for(let i in data.inside){
    let myData = data.inside[i].keyName;
  }
});

但你需要數據

{ 
 inside : [
             {keyName: ...}
          ]
}

作為data.inside[i]訪問 data.inside 的第i個索引,或者如果您將數據作為數組使用data[i]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM