【问题标题】:Dropdown filter in angularjsangularjs中的下拉过滤器
【发布时间】:2015-09-21 11:45:27
【问题描述】:

我有一个数据数组,我需要将其绑定到 angularjs 中的下拉列表。

$scope.offerFilter = [  {title :'Matching Ticket' , Status : '1'},
     {title :'Non-matched Ticket',Status : '2'},
     {title :'Rejected Ticket',Status :  '3'},
     {title: 'Not Sale', Status: '0'}]

我已将标题绑定到我的下拉列表。当我从下拉列表中选择选项时,我的页面没有被过滤。我不知道我哪里错了。

我的观点

<select ng-model="SelectedStatus" ng-options="type.Status as type.title for type in offerFilter" style="float:right;width:40%;font-family:'Segoe UI';font-size:12px;">
                    <option value="">All {{type.title}}</option>
                </select>
<md-list-item dir-paginate="ticket in ticketInventoryList.data.hits.hits | itemsPerPage:10 | filter : SelectedStatus">
            <div style="width:15%">
                <img alt="{{ ticket._source.SeriesName }}" ng-src="{{ ticket._source.ImagePath }}" class="md-avatar" style="width:90%" />

            </div>
     </md-list-item>

我的控制器:

我已将 ng-model 变量声明为 $scope.SelectedStatus='';

提前致谢。

【问题讨论】:

  • 您正在使用许多不常用的指令。可能是您编写的,或者它们来自某个图书馆。如果人们不理解您的代码,他们很难帮助您。因此,请创建一个工作示例,例如 plunker 或 js fiddle 来显示您的问题,以便人们可以轻松地帮助您
  • 我已经在此处提供了所有信息,并解释了我的问题。

标签: angularjs angularjs-ng-repeat


【解决方案1】:

希望对你有用

<select ng-model="SelectedStatus" ng-change="changeValue(SelectedStatus)" ng-options="type.Status as type.title for type in offerFilter" style="float:right;width:40%;font-family:'Segoe UI';font-size:12px;">
                    <option value="">All {{type.title}}</option>
                </select>

请在控制器中输入所有代码

$scope.isShow=false;
$scope.changeValue=function(selectedValue){
    if(condtion you want){
    $scope.isShow=false;
    $timeout(function(){
            $scope.isShow=true;
    },500);
    }
}

<md-list-item dir-paginate="ticket in ticketInventoryList.data.hits.hits | itemsPerPage:10 | filter : SelectedStatus" data-ng-if="isShow">
            <div style="width:15%">
                <img alt="{{ ticket._source.SeriesName }}" ng-src="{{ ticket._source.ImagePath }}" class="md-avatar" style="width:90%" />

            </div>
     </md-list-item>

选择值更改时您对刷新指令的更改。

【讨论】:

  • 它只是在点击下拉选项后显示数据列表。我的问题是我的视图页面没有根据下拉选择进行过滤
  • dir-paginate="ticket in filters = (mapList | filterMaps : ticketInventoryList.data.hits.hits : SelectedStatus) | itemsPerPage: 10 "。使用你的目录分页的这个地方
  • 我已经按照你建议的方式使用了,但仍然无法正常工作。 &lt;md-list-item dir-paginate="ticket in filtered = (mapList | filterMaps : ticketInventoryList.data.hits.hits : SelectedStatus) | itemsPerPage:10 " data-ng-if="isShow"&gt; &lt;div style="width:15%"&gt; &lt;img alt="{{ ticket._source.SeriesName }}" ng-src="{{ ticket._source.ImagePath }}" class="md-avatar" style="width:90%" /&gt; &lt;/div&gt;
  • 你试过这个吗? dir-paginate="ticket in filters = (mapList | filterMaps : ticketInventoryList.data.hits.hits | SelectedStatus) | itemsPerPage:10 "
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-17
  • 1970-01-01
  • 1970-01-01
  • 2020-05-10
相关资源
最近更新 更多