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'、名前: 'obj1'}、{someProperty: '2'、名前: 'obj2'} 'という名前が含まれていて、これを行います: '