简体   繁体   English

如何在Angular JS中按父属性过滤子属性?

[英]How can I filter children properties by parent property in Angular JS?

How can I filter the below JSON object so that I only display names that have a date of '01-2015'? 如何过滤下面的JSON对象,以便仅显示日期为'01 -2015'的名称? When I try using the filter method below I end up getting what looks like "[] []" in the HTML content. 当我尝试使用下面的filter方法时,最终得到的是HTML内容中的“ [] []”。 If there is a solution, how can I display each array item of names instead of having the HTML return ['Susan Hill', 'Petrona Morgan']? 如果有解决方案,该如何显示名称的每个数组项而不是让HTML返回['Susan Hill','Petrona Morgan']?

var annApp = angular.module('anniversaries', []);

<div ng-app="anniversaries" class="row" ng-controller="annList">
<div class="mdl-card__supporting-text text2" >
    <p ng-repeat="ann in anns">{{ ann.names | filter:{$:"01-2015"} }}</p>
</div>
<script>
annApp.controller('annList', function ($scope) {
  $scope.anns = [
    {'date':'01-2015','year': '45', 
    'names': ['Susan Hill', 'Petrona Morgan ']},
    {'date': '01-2015', 'year': '35',
    'names': ['Terisa Branson', 'Jo Fox', 'Genette McKown']}
  ];
}); 
</script>

Try 尝试

<p ng-repeat="ann in anns | filter: {date : '01-2015'}">
  <span ng-repeat="name in ann.names">{{name}}<br/></span>
</p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何过滤子对象的属性并返回带有在Javascript中传递过滤器的子对象的父对象? - How to filter on properties of children object and return the parent with children that passes the filter in Javascript? 如何用函数包装子属性? - How can I wrap a children properties with a function? 如何设置对象属性的属性?(js) - How I can set property of object properties?(js) 如何自动select儿童选项选择时选择父级选项JS,ZA565B176ECE81D91B5C08C08C39ADB65AF1Z - How can i auto select children option when selected parent option Js, Jquery 如何使用Angular JS根据索引过滤? - How can I filter according to index with Angular JS? Angular js选择父级和子级值 - Angular js Select Parent and Children Values 如何使用javascript在TreeTable中将多个子属性递归总结为其父属性 - How to recursively sum up multiple children properties to it parent property in TreeTable using javascript 创建对象时,如果该对象是该父对象的属性中的父对象的属性,是否可以计算该对象的属性数 - Can I count the number of properties of an object if this object is a property of parent object in the property of this parent object when creating 如何按2个不同的属性过滤? - How can I filter by 2 different properties? 在 JavaScript 中,如何访问子节点的属性? - In JavaScript, How can I access properties of children nodes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM