【问题标题】:Refresh content of the dropdown based on result根据结果​​刷新下拉菜单的内容
【发布时间】:2016-11-22 20:05:01
【问题描述】:

我正在尝试开发一个类似 Excel 的表格过滤器,其中可以跨列应用任意数量的过滤器。

请看看我的code in plunkr。这对于过滤数据非常有效。但我希望在更新数据时更新“过滤器”列表。我无法弄清楚如何解决这个问题。

.filter('inArray', function($filter){
return function(list, arrayFilter, element){
    if(arrayFilter){
        return $filter("filter")(list, function(listItem){
            return arrayFilter.indexOf(listItem[element]) != -1;
        });
    }
};

});

例如(来自 plunkr):
如果我们选择“印度”,它将返回 3 条记录,分别为 2、3 和 7 个月。我希望“月份”过滤器列表显示结果 (2,3,7) 中的值,而不是显示所有值。 如果您需要任何进一步的信息,请告诉我。

【问题讨论】:

  • 严重性选项应该“打开记录”是什么意思?我不明白这里应该发生什么。过滤器在您的 Plunker 中正常工作,您希望它接下来做什么?
  • 非常抱歉。 Stackoverflow 自动编辑的一些问题。我解释了我到底想要什么。请帮我解决这个问题。 @RaniRadcliff

标签: angularjs filter angular-ui-bootstrap dropdown bootstrap-table


【解决方案1】:

好的,这是一个完整的“hack”,我相信有更好的方法可以做到这一点,但这至少可以让您解决问题。我分叉了您的Plunker 并进行了一些更改。我在您的国家/地区列表中添加了ng-change 以显示或隐藏过滤的月份:

                                <div class="dt-buttons btn-group">
                                    Selected Countries:<br>
                                    <select size="4" multiple ng-multiple="true" ng-model="selectedCountries" ng-options="country for country in countryList" ng-change="filterMonths()"></select>
                                </div>
                                <div ng-show="!countryselected" class="dt-buttons btn-group">
                                    Selected Months:<br>
                                    <select size="10" multiple ng-multiple="true" ng-model="selectedMonths" ng-options="month for month in monthList"></select>
                                </div>
                                <div ng-show="countryselected" class="dt-buttons btn-group">
                                    Selected Months:<br>
                                    <select size="10" multiple ng-multiple="true" ng-model="monthsSelected"><option ng-repeat="f in filtered">{{f.month}}</option></select>
                                </div>

然后在控制器中,我添加了:

    $scope.countryselected = false;
$scope.filterMonths = function(){
  $scope.countryselected = true;
}

如果我想出更好的方法,我会编辑我的答案,但这至少应该能让你继续前进。祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-23
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    相关资源
    最近更新 更多