[英]Selecting all NG-Repeat iterations except the selected one
Is there a way to do a jQuery like selection of a particular iteration of an ng-repeat? 有没有一种方法可以像选择ng-repeat的特定迭代一样进行jQuery?
When editing a particular article I want all the other articles to be faded out so I'm using a function: 编辑特定文章时,我希望所有其他文章都淡出,因此我使用的是函数:
ng-click="edit(articleKey)"
And will be using ng-class to do the specified fading. 并且将使用ng-class进行指定的衰落。
How would I go about making the function in the controller have this behaviour? 我将如何使控制器中的功能具有这种行为?
You can use $index to do that. 您可以使用$ index做到这一点。
Something like this. 这样的事情。
<ion-list>
<ion-item ng-click="selected.value = $index" ng-repeat="item in items" ng-hide="selected.value === $index">
Hello, {{item}}!
</ion-item>
</ion-list>
Just store the selected value when clicked and instead of ng-hide you can use ng-class to fade out the elements, comparing them to the selected index. 只需在单击时存储选定的值,您就可以使用ng-class淡出元素,而不是ng-hide,将它们与选定的索引进行比较。
This should get you going: 这应该可以帮助您:
<tbody>
<tr ng-repeat="product in products">
<td ng-class="{'faded_out': !article[product.id].selected, 'faded_in': article[product.id].selected}" ng-click="edit('product.id')">{{ product.id }}</td>
</tr>
</tbody>
$scope.products = [{name: "All", articleKey: "212", selected = true},
{name: "Termi", articleKey: "4324" selected = true},
{name: "911", articleKey: "2323" selected = true}];
$scope.edit = function (articleKey){
for (var i = 0; i < $scope.products.length; i++) {
if ( $scope.products[i].articleKey === $scope.products[i].articleKey) {
$scope.products[i].selected = true;
} else {
$scope.products[i].selected =false;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.