![](/img/trans.png)
[英]angularjs 1.3 javascript animation works on ng-repeat but not ng-if
[英]How do I pass the DOM object (this) that contains an ng-repeat statement into the ng-if function? (Javascript/AngularJS)
我的页面上有一个ng-repeat,我需要过滤其中的项目。 为了进行过滤,我在其上方包括了一个隐藏字段,其中包含我需要使用的密钥。
<div class="filterProductsContainer">
<asp:HiddenField runat="server" ID="FilterKey"/>
<ul class="product_listing_component--results-list">
<li ng-if="isInCategory(product, $event)" ng-repeat="product in filterProducts">
<a href="{{product.link}}">
<img src="{{product.image}}" /></a>
</li>
</ul>
</div>
$scope.isInCategory = function (product, $event) {
console.log(product);
console.log($event);
var filterKey = $($event.target).parent(".filterProductsContainer").find("input[type='hidden'").val();
console.log(filterKey);
var targetProduct = $scope.products[product];
var foundMatch = false;
for (var tag in targetProduct.tags) {
var targetTag = targetProduct.tags[tag];
if (filterKey === targetTag.id) {
foundMatch = true;
}
if (foundMatch) {
break;
}
}
return foundMatch;
}
但是$ event最终为null。
尝试直接在ng-repeat中使用过滤器
<li ng-repeat="product in filterProducts | filter: {id: '<FilterKeyValue>'}" >
其中id
是您要用来过滤的product
对象的属性名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.