This question already has answers here:
AngularJs Remove duplicate elements in ng-repeat
                                
                                    (5个答案)
                                
                        
                                5年前关闭。
            
                    
我有这个json:

[
{
    "month": "Feb",
    "title": "Title 1",
    "status": "Closed"
},
{
    "month": "Feb",
    "title": "Title 2",
    "status": "Delayed"
},
{
    "month": "Feb",
    "title": "Title 3",
    "status": "Open"
},
{
    "month": "Mar",
    "title": "Title 4",
    "status": "Closed"
}


]

我试图用几个月来填充选择框:

<select id="month" ng-model="monthFilter" ng-options="task.month for task in tasks | filter: monthFilter">
    <option value="">MONTH</option>
</select>


我不知道我是否以正确的方式进行操作,但是很显然,它会返回所有数组月份的列表:Feb, Feb, Feb, Mar。我怎样才能使角度只返回Feb, Mar

一些帮助,将不胜感激。

最佳答案

ng-options="task.month for task in tasks | unique:'task.month'"


希望对您有用,或者至少可以引导您朝正确的方向发展。

编辑:尝试在这里寻找您需要的内容:Angular UI ~ UI.Utils Doc

09-07 13:01