基于select中的选项进行过滤时出现问题,然后使用多个字段过滤ng-repeat。如果我选择英语,我必须获得英语电影,如果我选择英语,印地语我必须同时收到英语和印地语电影。
这是我的代码
<div class="container languageSelect pull-right col-xs-12" ng-app="myApp" ng-controller="moviesCtrl">
<select id="selectTitle" ng-options="option for option in languageslist" ng-model="selectedLang.movielanguage" multiple="multiple"></select>
</div>
<div class="">
<figure class="movie" ng-repeat="record in movieslist | filter: selectedLang">
<a href="#!/movieHomePage" ng-click="showDetails(record)"><img height="300" width="192" class="poster" ng-src='{{record.imageurl}}' alt="{{record.moviename}} Image">
<figcaption class="moviename">{{record.moviename}}</figcaption></a>
</figure>
</div>
这是我的.Js文件
app.controller('moviesCtrl',['$scope', function($scope) {
$scope.selectedLang = { movielanguage:"" };
$scope.recordDetails= undefined;
$scope.languageslist = ["English", "Hindi","Kannada","Malayalam","Tamil", "Telugu"];
$scope.movieslist= [
{"movieId": "0001", "moviename" : "Aval", "imageurl" : "", "movielanguage":"Tamil" },
{"movieId": "0002", "moviename" : "Blade Runner", "imageurl" : "", "movielanguage":"English" },
{"movieId": "0003", "moviename" : "Geostorm", "imageurl" : "", "movielanguage":"English" },
{"movieId": "0004", "moviename" : "Golmaal Again", "imageurl" : "", "movielanguage":"Hindi" },
{"movieId": "0005", "moviename" : "ITTEFAQ", "imageurl" : "", "movielanguage":"Hindi" },
{"movieId": "0006", "moviename" : "Mersal", "imageurl" : "", "movielanguage":"tamil" },
{"movieId": "0011", "moviename" : "PSV Garuda Vega", "imageurl" : "", "movielanguage":"telugu" },
{"movieId": "0011", "moviename" : "Raja The Great", "imageurl" : "", "movielanguage":"telugu" },
{"movieId": "0007", "moviename" : "Secret Superstar", "imageurl" : "", "movielanguage":"hindi" },
{"movieId": "0008", "moviename" : "Solo", "imageurl" : "", "movielanguage":"malayalam" },
{"movieId": "0009", "moviename" : "The Foreigner", "imageurl" : "", "movielanguage":"english" },
{"movieId": "0010", "moviename" : "Thor Ragnarok", "imageurl" : "", "movielanguage":"english" },
{"movieId": "0011", "moviename" : "Villain", "imageurl" : "", "movielanguage":"malayalam" }
]
$scope.showDetails = function (record) {
$scope.model.recordDetails = record;
};
$(function () {
$('#selectTitle').multiselect({
width: 200,
nonSelectedText: 'Select Language',
includeSelectAllOption: true,
nSelectedText: 'Languages Selected',
});
});
}]);
答案 0 :(得分:1)
您可以在下拉选择列表中避免ng-repeat。您将使用ng-option,这将是一个更好的选项。
record in movieslist | filter: {movielanguage: "Tamil"}
Your code
record in movieslist | filter: {movielanguage: selectedLang.movielanguage}
<div class="">
<figure class="movie" ng-repeat="record in movieslist | filter: {movielanguage: selectedLang}">
<a href="#!/movieHomePage" ng-click="showDetails(record)"><img height="300" width="192" class="poster" ng-src='{{record.imageurl}}' alt="{{record.moviename}} Image">
<figcaption class="moviename">{{record.moviename}}</figcaption></a>
</figure>
</div>