[英]filter array values in angularjs
I have an arrays of values that contain the title names of different applications. 我有一个包含不同应用程序标题名称的值数组。
Example: 例:
$scope.badge = [{title: 'Incidents'},{title: 'News'}]
In the main page, where I place all the different apps, I would like to get the name for the specific app. 在主页上,我放置了所有不同的应用程序,我想获取特定应用程序的名称。
How can I filter the values so I can get the correct title for each app? 如何过滤值,以便为每个应用程序获取正确的标题?
Something like this: 像这样:
<span>{{badge.title}}</span>
UPDATE/ SOLUTION 更新/解决方案
I got it to work. 我知道了。 The solution is below: 解决方案如下:
$scope.badges = {
titles: [
{id: 2, name: 'Incidents'},
{id: 3, name: 'News'}
]
};
<div ng-repeat="title in badges.titles | filter:{id:2}">
<ul>
<li>
<a class="{{title.name}}" ng-click="addNew()">Add New {{title.name}}</a>
</li>
</ul>
For my current purposes, that did it for me. 就我当前的目的而言,这对我来说是可行的。 If there is a more elegant, dynamic solution, I would like to learn it. 如果有一个更优雅,更动态的解决方案,我想学习一下。
Many thanks to all. 非常感谢所有人。
If the browsers you're using support Array.prototype.find , you can do something like this. 如果您使用的浏览器支持Array.prototype.find ,则可以执行以下操作。
$scope.badge = [{label: 'Incidents', appName: 'incident'},{label: 'News', appName: 'news'}];
//I'm not positive how to get the app name, but APP_NAME can be replaced with that
<span>{{badge.find(function(option) { return option.appName == APP_NAME})}}</span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.