0
我在我的頁面上有一個ng-repeat,我需要過濾其中的項目。爲了過濾的目的,我在其上面包含了一個包含我需要使用的密鑰的隱藏字段。如何將包含ng-repeat語句的DOM對象(this)傳遞給ng-if函數? (Javascript/AngularJS)
<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;
}
$事件最終被空,但。
它將如何解釋FilterKeyValue?這是從哪裏來的? –
這是過濾的實際值,在你的情況下,我猜它是FilterKey隱藏字段的值。假設'filterProducts'包含'[{someProperty:'1',name:'obj1'},{someProperty:'2',name:'obj2'}]'並且您這樣做:'