带条件的角度ng-option过滤

时间:2017-06-29 11:33:44

标签: javascript jquery angularjs asp.net-mvc

以下列表希望在条件为wp_get_recent_posts

的下拉列表中进行绑定
type="0"

然后将如何修改下面的代码

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

1 个答案:

答案 0 :(得分:1)

您可以filterType='0',html迭代ListPrintDestination

<强>演示:

&#13;
&#13;
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"
  }];
});
&#13;
<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>
&#13;
&#13;
&#13;