我有两个我正在调用的Web API。第一个api类型中的每个值都有ID
,需要用于过滤第二个api,即Category。 JSON
位于以下位置:
// Types
[{"ID":1,"Text":"Hardware","Description":"Hardware"},
{"ID":2,"Text":"Software,"Description":"Software"}"}];
// Categories
[{"ID":1,"TypeID":1,"ParentID":0,"Name":"Printing"},
{"ID":2,"TypeID":1,"ParentID":1,"Name":"Toner"}]
答案 0 :(得分:0)
首先,您必须存储将用于过滤另一个数组的selectedTypeID,而不是在第二个数组中调用Angular $filter。
Sintax:
$filter('filter')(array, expression, comparator)
e.g:
$filter('filter')($scope.categories, {TypeID: $scope.selectedTypeID}, comparator)
答案 1 :(得分:0)
我认为你问的是:*如何根据另一个select
输入中的选择动态填充select
输入?
我认为你可以采取两种方式。如果总数据不多(例如Categories
),则可以在第二组数据上使用filter
。 https://docs.angularjs.org/api/ng/filter/filter#!
您可以在HTML或控制器中执行此操作!
<!-- HTML Page -->
<select>
<option ng-repeat="value in values | filter..." value=value>
</select>
// controller.js
values = ($filter('filter')(result.Values, {Id: $routeParams.Id}));
如果要过滤大量数据,请考虑将您的号码推迟到Category
API,直到选择Type
为止。
如果没有看到控制器/ HTML等等,很难给出具体答案,但我认为这会让你朝着正确的方向前进。
答案 2 :(得分:0)
$scope.countries = CustomerService.getCountry();
$scope.getCountryStates = function(){
$scope.sates = CustomerService.getCountryState($scope.customer.Country);
$scope.cities =[];
};
<select ng-model="customer.State"
ng-options="x.Id as x.state for x in sates"
ng-change = "getStateCities()"
class="form-control"
ng-required="true"
id="state">
<option value="">-- Choose State --</option>
</select>
<select ng-model="customer.City"
ng-options="x.Id as x.city for x in cities"
class="form-control"
ng-required="true"
id="city">
<option value="">-- Choose City --</option>
</select>