选择除选中的NG-Repeat迭代之外的所有NG-Repeat迭代
Selecting all NG-Repeat iterations except the selected one
是否有一种方法可以像jQuery一样选择ng-repeat的特定迭代?
当编辑一篇特定的文章时,我想让所有其他的文章都褪色,所以我使用了一个函数:
ng-click="edit(articleKey)"
并且将使用ng-class来执行指定的衰落。
我该如何使控制器中的函数具有这种行为?
你可以使用$index。
就像这样。
<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>
在点击时存储选中的值,而不是ng-hide,您可以使用ng-class来淡出元素,将它们与选定的索引进行比较。
这应该会让你开始:
<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;
}
}
}
相关文章:
- AngularJs Datatables 无法使用 ng-repeat 在 html 上迭代列
- AngularJS Ng-Repeat不迭代$Scope中的项目
- AngularJs:我想从数组或列表中添加一个类,用于ng-repeat中的每次迭代
- 有没有办法重新映射使用 ng-repeat 迭代的对象的关键值
- 如何为由 ng-repeat 迭代的每个名称和值添加单独的宽度
- 在AngularJS中使用ng repeat调用和迭代函数返回值
- ng Angular.js中的Repeat不根据json中的items索引进行迭代
- 使用 AngularJS(Ng-Repeat) 迭代多维 Json
- 将json对象转换为数组,使用Javascript迭代ng-repeat
- 使用Angular ng-repeat迭代对象数组的非均匀性
- 图形化地隐藏一些使用ng-repeat迭代的项
- AngularJS使用ng-repeat迭代多层数组
- 选择除选中的NG-Repeat迭代之外的所有NG-Repeat迭代
- Angular ng-repeat的最佳实践:只监视特定迭代中的更新
- 如何在ng-repeat的每次迭代中过滤嵌套数组对象?
- 在Angular.js中,如何在点击时使用ng-repeat迭代对象列表中修改元素的属性?
- AngularJS:自定义迭代/数据转换和分组…当简单的ng-repeat只是won'
- 只有在迭代JSON对象时,键才使用更简洁的ng-repeat语法
- 在AngularJS中限制ng-repeat迭代
- 迭代ng-在AngularJs中只重复X次