我有一个小的图库,其中包含一个搜索框,用户单击图像时会打开一个带有相同图像的灯箱。
问题在于用户筛选结果后(搜索输入),单击仍然保留列表中的索引,而没有筛选器,这使得灯箱打开错误的图像。有人知道如何解决吗?
谢谢。
基本上,我将$index传递给一个函数,该函数在$scope.list[lb.index]中打开该项。
我的代码:
HTML
<input type="text" ng-model="query.name" />
<ul class="list" ng-show="list.length>0">
<li ng-repeat="item in list | filter:query">
<a class="img" ng-style="{'background-image':'url(/uploads/<%item.image%>)'}" ng-click="openLB($index)"></a>
</li>
</ul>
<div class="lightbox" ng-if="lb.show">
<a class="prev" ng-show="list.length>1" ng-click="changeItemLB(lb.index, 'prev')"></a>
<a class="next" ng-show="list.length>1" ng-click="changeItemLB(lb.index, 'next')"></a>
<div class="holder">
<img ng-if="list[lb.index].image.length" ng-src="/uploads/<%list[lb.index].image%>" />
</div>
</div>
Angular
$scope.openLB = function(index) {
$scope.lb.show = true;
$scope.lb.index = index;
};
$scope.changeItemLB = function(index, action) {
var tot = $scope.list.length-1,
goto = 0;
if(action=='prev') goto = index==0 ? tot : index-1;
if(action=='next') goto = index==tot ? 0 : index+1;
$scope.openLB(goto);
}
问题在于用户筛选结果后(搜索输入),单击仍然保留列表中的索引,而没有筛选器,这使得灯箱打开错误的图像。有人知道如何解决吗?
谢谢。