簡體   English   中英

從ng-option訪問對象

[英]Accessing an object from ng-option

關於蜜蜂訪問對象的問題很多,但我找不到能回答我問題的對象。

我有一個動態創建的對象,像這樣:

{
    id: "ISO 19115:MD_Metadata:identificationInfo:extent:temporalElement:extent",
    value: "ISO   19115:MD_Metadata:identificationInfo:extent:temporalElement:extent:endPosition",
    begin: "ISO 19115:MD_Metadata:identificationInfo:extent:temporalElement:extent",
    ...
}

我想在ng-options(angularJS)中顯示第二個參數的對(id-ISO 19115:MD ...,值-ISO 19115:MD ...),這是通過第一個參數的路徑。

所以我想知道這樣的事情是否可行:

 <select ng-model='selectedtype' ng-options="(item[0] + item[1]) for item in types">
        <option value="">select type</option> 
 </select>

請注意,我的對象在$scope.types

這是行不通的,因此是否有解決方案,例如用於訪問name:value對的指定關鍵字。

我知道這對於設計一個對象是很糟糕的,我應該嘗試這樣的事情:

{
 [
    {
        'name': 'id',
        'value':'ISO 19115 ...',
    },
    ....
 ]
}

但是,如果可能的話,我將不勝感激。

ng-options支持字符串連接。 因此您可以輕松使用類似

ng-options="'id-'+item.id+', value-'+item.value for item in types"

演示: http //plnkr.co/edit/XHXKnNJOaDEAITtkI3HC?p = preview

您可以使用以下格式來訪問對象鍵值對:

ng-options="key as key+': '+value for (key, value) in types"

另請參見此簡短演示

暫無
暫無

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

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