有什么方法可以在 angular 中的 obj obj 获取数据吗?

Is there any way to fetch data at obj obj in angular?

有没有办法在 obj obj 获取数据(通过 id)?

示例:

  hello(){
    this._shelveService.getShelveDataById(this.route.snapshot.params.id).subscribe(data => {
      console.log(data);

  this._shelveForm = this.fb.group({
    id_shelve:[data['id_shelve']],
    description_shelve:[data['description_shelve']],
    war_id:this.fb.group({
      id_warehouse: [data['war_id.id_warehouse']]
    })
 })
    })
  }

如何获取id_warehouse的值?

我可以使用 hello() 函数 获取值 id_shelve 和 description_shelve,但是如果我输入:

war_id:this.fb.group({
  id_warehouse: [data['war_id']] 

我得到结果 Obj Ojb

json :

{
    "id_shelve": 1,
    "description_shelve": "Περιγράφη Ραφίου!!!",
    "war_id": {
        "id_warehouse": 1,
        "description_warehouse": "Περιγράφη Αποθήκης!!!"
    }
}

任何帮助;

您可以通过以下两种方法之一解决此问题:

a) 点符号:

this._shelveForm = this.fb.group({
    id_shelve: [data['id_shelve']],
    description_shelve: [data['description_shelve']],
    war_id: this.fb.group({
        id_warehouse: [data.war_id.id_warehouse],
        description_warehouse: [data.war_id.description_warehouse]
    })
});

b) 方括号表示法:

this._shelveForm = this.fb.group({
    id_shelve: [data['id_shelve']],
    description_shelve: [data['description_shelve']],
    war_id: this.fb.group({
        id_warehouse: [data['war_id']['id_warehouse']],
        description_warehouse: [data['war_id']['description_warehouse']]
    })
});

替换:

war_id:this.fb.group({
  id_warehouse: [data['war_id']] 

war_id:this.fb.group({
  id_warehouse: [data['war_id']['id_warehouse']]