角度搜索未正确过滤

时间:2016-09-12 19:00:42

标签: angularjs json

我有一个JSON数据列表,我需要通过键入名称来过滤。结果应该只显示结果中具有该名称的那些列表。它目前只是隐藏其他名称,仍然显示所有其他列表。

如何设置过滤器,以便在输入演员名称时,它只显示演员列出的电影列表?

这是用于显示列表的标记,以及Angular过滤器代码:

<div class="row" ng-repeat="movies in results | filter:genre">
    <div class="col-lg-12">
        <div class="well well-sm">
            <div class="row">
                <div class="col-xs-3 col-md-3 text-center">
                    <img src="" alt="poster"
                        class="img-rounded img-responsive" />
                </div>
                <div class="col-xs-9 col-md-9 section-box">
                    <h2>
                        {{movies.Name}}
                    </h2>
                    <div class="row rating-desc">
                        <div class="col-md-12">
                            <span class="glyphicon glyphicon-time"></span>{{movies.Duration}}<span class="separator">|</span>
                            <span class="glyphicon glyphicon-signal"></span>{{movies.Rank}}<span class="separator">|</span>
                            <a class="bookMovie" href="http://www.fandango.com/{{movies.Name}}">Book Now!</a>
                        </div>
                    </div>
                    <hr>
                    <p>
                        {{movies.Description}}
                    </p>
                    <p ng-repeat="actor in movies.Actors | filter:actor" >
                     <span ng-bind="actor"></span>
                    </p>
                    <hr />
                </div>
            </div>
        </div>
    </div>
  </div>

可以在此plunker中看到JSON和其余代码: https://plnkr.co/edit/ZmxaSRg9ir0qlNNtOyCd?p=preview

2 个答案:

答案 0 :(得分:2)

您可以按此对象进行过滤filter:{ Genres: genre, Actors: actor }

<div class="row" ng-repeat="movies in results | filter:{ Genres: genre, Actors: actor }">

plnkr link

答案 1 :(得分:0)

那是因为您应该将actor过滤器放在父ng-repeat中,请查看以下plnkr:

https://plnkr.co/edit/k1JVXL0Cpxysjhn2tNx7?p=preview

<div class="row" ng-repeat="movies in results | filter:actor | filter:genre">