过滤下拉列表中的选定项目

坦率

我正在尝试使我的{{client.tenant}}成为以后过滤我的桌子的来源。该表格仅应基于我的下拉列表中的选择查看客户1或客户2。我感到下拉列表中的输入没有存储在任何地方。你有一些提示,我做错了什么吗?下来是我代码中的示例。我测试了很多,所以对代码感到抱歉。

    <body>
    <div class="container" ng-controller="menuController">
        <select>
  <option ng-model="dropdownString" ng-repeat="client in products | unique:'tenant'">{{client.tenant}}</option>
</select>
        <div class="tab-content">
            <ul class="media-list tab-pane fade in active">
                <div class="row row-content">
                    <div class="col-xs-12">
                        <ul class="media-list">
                            <li class="media">
                                <div class="media-left media-middle">
                                </div>
                                <div class="media-body">
                                    <table>
                                        <tr>
                                            <th class="table-1">Product description</th>
                                            <th>SKU</th>
                                            <th>Tenant</th>
                                            <th>Select</th>
                                        </tr>
                                        <tr ng-repeat="product in products | searchFor:searchString">
                                            <td>{{product.description}}</td>
                                            <td>{{product.sku}}</td>
                                            <td>{{product.tenant}}</td>
                                            <td><input type="checkbox"></td>
                                        </tr>
                                    </table>
                                </div>
                            </li>
                        </ul>
            </ul>
            </div>
            </div>
        </div>
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
    <script>
        var app = angular.module('productBackend', []);
        app.controller('menuController', function ($scope, $http) {
            $scope.search=[];
            $http.get('./scripts/products.json')
                .then(function (res) {
                    $scope.products = res.data;
                });
        });

        app.filter('searchFor', function () {
            return function (arr, searchString) {
                if (!searchString) {
                    return arr;
                }
                var result = [];
                searchString = searchString.toLowerCase();
                angular.forEach(arr, function (item) {
                    if (item.tenant.toLowerCase().indexOf(searchString) !== -1) {
                        result.push(item);
                    }
                });
                return result;
            };
        });

app.filter('unique', function() {
   return function(collection, keyname) {
      var output = [], 
          keys = [];
      angular.forEach(collection, function(item) {
          var key = item[keyname];
          if(keys.indexOf(key) === -1) {
              keys.push(key); 
              output.push(item);
          }
      });
      return output;
   };
});

app.controller('ExampleController', ['$scope', function($scope) {
   $scope.data = {
    singleSelect: null,
    multipleSelect: [],
    option1: 'option-1'
   };

   $scope.forceUnknownOption = function() {
     $scope.data.singleSelect = 'nonsense';
   };
}]);
    </script>
</body>

Json文件:

[{
    "sku": "S-MLX-SEC-002",
    "description": "Intrusion Prevention",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-MCA-007",
    "description": "Microsoft Lync Enterprise - Private Cloud",
    "tenant": "Customer 1"
},{
    "sku": "S-MLX-SEC-002",
    "description": "Intrusion Prevention",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-SEC-004",
    "description": "Local privacy compliance",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-S02-100",
    "description": "Location based Access",
    "tenant": "Customer 1"
},{
    "sku": "S-MLX-SEC-002",
    "description": "Intrusion Prevention",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-S02-510",
    "description": "Two factor authentication - Hard Token Security",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-MCA-007",
    "description": "Microsoft Lync Enterprise - Private Cloud",
    "tenant": "Customer 1"
},{
    "sku": "S-MLX-CHG-001",
    "description": "Changes level Business - for Global Desktop Bundel",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-GLD-003",
    "description": "Global Desktop Business Bundel - Performance - Private Cloud",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-GLD-012",
    "description": "Global Desktop Foundation - Standard - Private Cloud",
    "tenant": "Customer 1"
},{
    "sku": "S-MLX-OFF-001",
    "description": "Microsoft Office Standard - Private Cloud",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-LOB-824",
    "description": "Exact Financials (CL) - Private Cloud",
    "tenant": "Customer 1"
}, {
    "sku": "S-MLX-MCA-007",
    "description": "Microsoft Lync Enterprise - Private Cloud",
    "tenant": "Customer 2"
},{
    "sku": "S-MLX-SEC-002",
    "description": "Intrusion Prevention",
    "tenant": "Customer 2"
}, {
    "sku": "S-MLX-SEC-004",
    "description": "Local privacy compliance",
    "tenant": "Customer 2"
}, {
    "sku": "S-MLX-S02-100",
    "description": "Location based Access",
    "tenant": "Customer 2"
},{
    "sku": "S-MLX-SEC-002",
    "description": "Intrusion Prevention",
    "tenant": "Customer 2"
}, {
    "sku": "S-MLX-S02-510",
    "description": "Two factor authentication - Hard Token Security",
    "tenant": "Customer 2"
}, {
    "sku": "S-MLX-MCA-007",
    "description": "Microsoft Lync Enterprise - Private Cloud",
    "tenant": "Customer 2"
},{
    "sku": "S-MLX-CHG-001",
    "description": "Changes level Business - for Global Desktop Bundel",
    "tenant": "Customer 2"
}, {
    "sku": "S-MLX-GLD-003",
    "description": "Global Desktop Business Bundel - Performance - Private Cloud",
    "tenant": "Customer 2"
}, {
    "sku": "S-MLX-GLD-012",
    "description": "Global Desktop Foundation - Standard - Private Cloud",
    "tenant": "Customer 2"
},{
    "sku": "S-MLX-OFF-001",
    "description": "Microsoft Office Standard - Private Cloud",
    "tenant": "Customer 2"
}, {
    "sku": "S-MLX-LOB-824",
    "description": "Exact Financials (CL) - Private Cloud",
    "tenant": "Customer 2"
}]

Plunkr https://embed.plnkr.co/hfB75e6w9sYZzDkwyh24/

安息日

您只需更改以下代码

 <select>
   <option ng-model="dropdownString" ng-repeat="client in products | unique:'tenant'">{{client.tenant}}</option>
  </select>

 <select ng-model="dropdownString" >
     <option ng-repeat="client in products | unique:'tenant'">{{client.tenant}}</option>
  </select>

我不确定它是否会工作。这就是我解决您问题的方法。我的代码如下:

的HTML

<input type="text" class="search" ng-model="searchx.sku" placeholder="Enter your search terms" />


<select ng-model="searchx.tenant">
    <option ng-repeat="client in products | unique:'tenant'">{{client.tenant}}</option>
</select>

<div class="tab-content">
    <ul class="media-list tab-pane fade in active">
        <div class="row row-content">
            <div class="col-xs-12">
               <ul class="media-list">
                        <li class="media">
                            <div class="media-left media-middle">
                            </div>
                            <div class="media-body">
                                <table>
                                    <tr>
                                        <th class="table-1">Product description</th>
                                        <th>SKU</th>
                                        <th>Tenant</th>
                                        <th>Select</th>
                                    </tr>
                                    <tr ng-repeat="product in products | filter: searchx">
                                        <td>{{product.description}}</td>
                                        <td>{{product.sku}}</td>
                                        <td>{{product.tenant}}</td>
                                        <td><input type="checkbox"></td>
                                    </tr>
                                </table>
                            </div>
                        </li>
                    </ul>
        </ul>
        </div>

Angular.js

 var app = angular.module('productBackend', []);

 app.controller('menuController', function ($scope, $http) {

       $scope.searchx = {};   

        $scope.search=[];
        $http.get('./products.json')
            .then(function (res) {
                $scope.products = res.data;
            });  
 });


 app.filter('unique', function() {
        // same code
 });

 app.controller('ExampleController', ['$scope', function($scope) {
     // same code
 }]);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何访问“隐藏代码”中的下拉列表中的选定项目?

来自分类Dev

根据下拉列表中的选定项目以编程方式更改值

来自分类Dev

在纸张元素下拉列表中检索选定的项目

来自分类Dev

使用下拉列表过滤项目

来自分类Dev

mvc按下拉列表过滤选定的文本

来自分类Dev

更改 sql 表中的两个下拉列表选定项目,但都获得相同的选定值

来自分类Dev

React-如何过滤下拉列表中的项目

来自分类Dev

通过 JQuery 选定项目列表过滤

来自分类Dev

如何从jquery.tablesorter.js中的列过滤器下拉列表中获取选定的选项

来自分类Dev

将下拉列表中的选定项目文本添加到gridview中的特定列

来自分类Dev

显示复选框项目列表(选定的下拉项目除外)

来自分类Dev

如何根据选定的下拉项目生成项目列表?

来自分类Dev

如何将下拉列表中的选定项目ID传递给控制器的操作?

来自分类Dev

C#从对象的下拉列表中检索选定的项目作为对象

来自分类Dev

从选择多个=“多个”选项下拉列表中获取所有选定项目的名称

来自分类Dev

从下拉列表中检索选定的枚举

来自分类Dev

从PHP的下拉列表中获取选定的文本

来自分类Dev

从PHP的下拉列表中获取选定的文本

来自分类Dev

计算GridView中的选定下拉列表

来自分类Dev

从Laravel的下拉列表中获取选定的值

来自分类Dev

使用下拉列表html中的选定值

来自分类Dev

从PHP的下拉列表中获取选定的值

来自分类Dev

从下拉列表中获取选定的值

来自分类Dev

微调器中的选定项目应以字符串数组而不是下拉列表中的位置映射项目名称

来自分类Dev

使用下拉列表从mysql数据库中获取数据,然后使用搜索功能从选定的下拉列表选项中过滤数据

来自分类Dev

在下拉列表中查找项目并将其设置为.asp.net MVC 4中的选定项

来自分类Dev

Ruby on Rails Search归档下拉列表,可过滤表中的项目

来自分类Dev

从列表中的选定项目获取属性值

来自分类Dev

如何从RecyclerView列表中获取选定的项目?

Related 相关文章

  1. 1

    如何访问“隐藏代码”中的下拉列表中的选定项目?

  2. 2

    根据下拉列表中的选定项目以编程方式更改值

  3. 3

    在纸张元素下拉列表中检索选定的项目

  4. 4

    使用下拉列表过滤项目

  5. 5

    mvc按下拉列表过滤选定的文本

  6. 6

    更改 sql 表中的两个下拉列表选定项目,但都获得相同的选定值

  7. 7

    React-如何过滤下拉列表中的项目

  8. 8

    通过 JQuery 选定项目列表过滤

  9. 9

    如何从jquery.tablesorter.js中的列过滤器下拉列表中获取选定的选项

  10. 10

    将下拉列表中的选定项目文本添加到gridview中的特定列

  11. 11

    显示复选框项目列表(选定的下拉项目除外)

  12. 12

    如何根据选定的下拉项目生成项目列表?

  13. 13

    如何将下拉列表中的选定项目ID传递给控制器的操作?

  14. 14

    C#从对象的下拉列表中检索选定的项目作为对象

  15. 15

    从选择多个=“多个”选项下拉列表中获取所有选定项目的名称

  16. 16

    从下拉列表中检索选定的枚举

  17. 17

    从PHP的下拉列表中获取选定的文本

  18. 18

    从PHP的下拉列表中获取选定的文本

  19. 19

    计算GridView中的选定下拉列表

  20. 20

    从Laravel的下拉列表中获取选定的值

  21. 21

    使用下拉列表html中的选定值

  22. 22

    从PHP的下拉列表中获取选定的值

  23. 23

    从下拉列表中获取选定的值

  24. 24

    微调器中的选定项目应以字符串数组而不是下拉列表中的位置映射项目名称

  25. 25

    使用下拉列表从mysql数据库中获取数据,然后使用搜索功能从选定的下拉列表选项中过滤数据

  26. 26

    在下拉列表中查找项目并将其设置为.asp.net MVC 4中的选定项

  27. 27

    Ruby on Rails Search归档下拉列表,可过滤表中的项目

  28. 28

    从列表中的选定项目获取属性值

  29. 29

    如何从RecyclerView列表中获取选定的项目?

热门标签

归档