0
由於標題非常清楚地表明,我想通讀一組對象並創建一個定製的下拉列表。自定義下拉列表中包含一個錨定標題作爲默認值和一個顯示值的列表。該結構如下:使用數組中的對象的鍵創建下拉列表
<div class="sort-select">
<a href="" ng-click="showList =! showList;" ng-init="showList=false;">
Sort By: <span class="info sort-state">Closest Match</span>
</a>
<ul ng-class="{'animate-list':showList}" ng-repeat = "sortByOption in healthResultsInfo.sortBy">
<li ng-repeat = "(key,value) in sortByOption"><a href="{{value[0]}}">{{key}}</a></li>
</ul>
</div>
的JSON結構如下:
"sortBy": [
{
"Relevance": "/shop?ns=relevance",
"default": "true",
"selected": "true"
},
{
"Name A-Z": "/shop?ns=relevance",
"default": "false",
"selected": "true"
}
]
正如你可以看到我已經試圖獲取值,但它是相當困難的,因爲我需要的鍵,即我的下拉選項中的「名稱AZ」或「相關性」。還需要使用默認屬性來選擇默認值。
我不確定格式化選項。另外,第一個選項總是處於頂端並不是必需的。另外,我需要在錨標記中選擇默認值爲true的值。對不起,但你的解決方案是不夠的。謝謝你嘗試。 –