簡體   English   中英

在選擇的 Dropwdown angular 中顯示嵌套的 json

[英]Display Nested json in select Dropwdown angular

我是 angular 的新手,正在努力在選擇下拉列表中顯示嵌套的 json 對象。 這是我的 json 對象。

[
  { 
    "cuisine":{ 
      "cuisine_id":1035,
      "cuisine_name":"Afghan"
    }
  },
  { 
    "cuisine":{ 
      "cuisine_id":1,
      "cuisine_name":"American"
    }
  }
]

在我的組件 HTML 中,我像這樣顯示

<select class="form-control dropdown" name="processTemplate" id="processTemplate">
  <option *ngFor="let cuisineList of cusine1 | keyvalue">
     {{ cuisineList.value.cuisine_name | json }}
   </option>
 </select>  

我想在選擇下拉菜單中只顯示菜名。 不知道我哪里出錯了。 任何幫助深表感謝

用:

{{ cuisineList.value.cuisine.cuisine_name }}

因為你需要給每個對象的訪問cuisine_name。

像這樣嘗試:

<select class="form-control dropdown" name="processTemplate" id="processTemplate">
  <option *ngFor="let cuisineList of cusine1 | keyvalue">
     {{ cuisineList.value.cuisine.cuisine_name }}
  </option>
</select>

工作演示

在變量中獲取 json 數組。 讓我們的變量是菜系 現在按照片段。

<select class="form-control dropdown" name="processTemplate" id="processTemplate">
  <option *ngFor="let cuisineList of cuisines">
     {{ cuisineList.cuisine.cuisine_name}}
   </option>
 </select> 

暫無
暫無

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

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