【发布时间】:2015-07-31 07:23:51
【问题描述】:
在这个 JSFiddle (https://jsfiddle.net/eug0taf9/9/) 中,我选择了一个评级并希望显示一个图像。
发生了什么?
当我选择评级“高”时,会显示 2 张图片而不是 1 张,因为过滤器正在捕捉类别“高”并且还描述类别“低”中的图像的“高”。
我预计会发生什么?
在选择评级“高”时,我只想过滤类别。我也不需要按描述过滤。
关于如何解决这个问题的任何建议?
HTML 代码:
<div ng-app="myApp" ng-controller="myCtrl">
<span>Select a rating</span>
<select ng-model="catselect"
ng-options="category for category in imageCategories"
ng-change="valueSelected(catselect)">
<option value>All</option>
</select>
<!--<p>Select <input ng-model="categories"/></p>-->
<ul class="photosmenu">
<li ng-repeat="image in images | filter : catselect" ng-click="setCurrentImage(image)">
<img ng-src="{{image.image}}" alt="{{image.stars}}" width="300px"/>
</li>
</ul><!-- End of List -->
</div>
角度代码:
var mod = angular.module("myApp", []);
mod.controller("myCtrl", function($scope){
$scope.images = [
{category: 'High', image: 'img/1.png', description: 'Random Photo', stars: '4/5'},
{category: 'Medium', image: 'img/6.png', description: 'ApplePhoto', stars: '3/5'},
{category: 'Low', image: 'img/13.png', description: 'High Top Photo', stars: '2/5'},
{category: 'None', image: 'img/16.png', description: 'Kilt Photo', stars: '0/5'}];
$scope.currentImage = $scope.images[0];
$scope.imageCategories = ["High", "Medium", "Low", "None"];
$scope.valueSelected = function (value) {
if (value === null) {
$scope.catselect = undefined;
}
};
});
【问题讨论】:
标签: angularjs angularjs-ng-repeat angularjs-filter