javascript - 防止数组中的 Angular 返回重复字符串

标签 javascript angularjs

我有这个 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 。我怎样才能让 Angular 只返回我Feb, Mar

一些帮助将不胜感激。

最佳答案

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

希望这对您有用,或者至少引导您走向正确的方向。

编辑:尝试在此处查找您需要的内容:Angular UI ~ UI.Utils Doc

关于javascript - 防止数组中的 Angular 返回重复字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26611304/

相关文章:

javascript - Immutability 和 Singleton 解决的是同一个目的吗?

javascript - 在 Javascript 中,对象根据其声明引用什么?

javascript - 是否可以通过函数更改类的样式属性?

当模型值不在选项中时,AngularJS select 不会出错

javascript - 使用Angular的$http服务调用js文件?

angularjs - 在 Angular 2 应用程序中使用本地 npm 存储库中的组件

javascript - Node express : Requests are taking Top-level domain as the subdomain ? ?

javascript - MVC webgrid 列宽?

javascript - src 属性的 Angular 插值错误

javascript - AngularJS 在事件处理程序(Jasmine)之后使用异步请求测试 Controller