【问题标题】:Angular ng-option filtering with a condition带有条件的 Angular ng-option 过滤
【发布时间】:2017-12-03 02:06:53
【问题描述】:

以下列表要在下拉列表中绑定条件type="0"

 $scope.ListPrintDestination = [{ id: "0", Name: "Printer",Type:"0" }, { id: "1", Name: "Windows" ,Type:"0"}, { id: "2", Name: "No Print" ,Type:"1"}];

那么如何修改下面的代码

<select ng-model="num" ng-options="lst as lst.AcNo for lst in lstPrint track by lst.AcNo">
    <option selected="selected">select</option>
</select>

【问题讨论】:

    标签: javascript jquery angularjs asp.net-mvc


    【解决方案1】:

    您可以将filter 用于Type='0',并在html 中迭代ListPrintDestination

    演示:

    var myApp = angular.module('myApp', []);
    
    myApp.controller('MyCtrl', function MyCtrl($scope) {
      $scope.ListPrintDestination = [{
        id: "0",
        Name: "Printer",
        Type: "0"
      }, {
        id: "1",
        Name: "Windows",
        Type: "0"
      }, {
        id: "2",
        Name: "No Print",
        Type: "1"
      }];
    });
    <script src="https://code.angularjs.org/1.5.2/angular.js"></script>
    <div ng-app="myApp" ng-controller="MyCtrl">
      <select ng-model="num" ng-options="lst as lst.Name for lst in ListPrintDestination | filter : {Type : '0'} ">
        <option selected="selected">select</option>
      </select>
    </div>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 2017-02-21
      相关资源
      最近更新 更多