AngularJS - 如何访问到下一个项目从纳克重复控制器 [英] AngularJS - How to access to the next item from a ng-repeat in the controller

查看:179
本文介绍了AngularJS - 如何访问到下一个项目从纳克重复控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上的一个按钮,当点击进入到下一个项目的参数在屏幕上。

I'd like to access to the parameters of the next item on screen when clicking on a button.

我用的NG-重复在我的HTML文件:

I use a ng-repeat in my html file:

<li ng-repeat="item in items | filter:query" ng-show="isSelected($index)">
    <a href="" ng-click="itemNext()"><img src="xxx.jpg" /></a>
</li>

和一个循环在我的控制器索引:

And the index in my Controller with a loop:

$scope.itemNext = function () {
    $scope._Index = ($scope._Index < $scope.nbItems - 1) ? ++$scope._Index : 0;
    $scope.functionToCallWithNextItem(nextItem.param1);
};

一个简单的 $ scope.items [$ scope._Index] .param1 而不是 nextItem.param1 止跌 ŧ工作的数据进行过滤,所以 $指数+ 1 $ scope.items 不一定是好的

A simple $scope.items[$scope._Index].param1 instead of nextItem.param1 wouldn't work as the data is filtered so $index+1 from $scope.items isn't necessarily the good one.

任何想法?

推荐答案

您可以将过滤后的数据分配给一个变​​量:

You can assign your filtered data to a variable:

<li ng-repeat="item in (filteredItems = (items | filter:query))">

然后使用 $指数+ 1 来得到下一个项目:

<a ng-click="itemNext(filteredItems[$index + 1])">

演示: http://plnkr.co/edit/OdL5rIxtTEHnQCC3g4LS?p=$p$pview

这篇关于AngularJS - 如何访问到下一个项目从纳克重复控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆