Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用angularjs更改另一个select标记的值?_Javascript_Jquery_Angularjs_Ui Select - Fatal编程技术网

Javascript 如何使用angularjs更改另一个select标记的值?

Javascript 如何使用angularjs更改另一个select标记的值?,javascript,jquery,angularjs,ui-select,Javascript,Jquery,Angularjs,Ui Select,我正在调用两个Web API。第一个api类型中的每个值都有一个ID,需要使用该ID来过滤属于类别的第二个api。JSON的JSON如下: // Types [{"ID":1,"Text":"Hardware","Description":"Hardware"}, {"ID":2,"Text":"Software,"Description":"Software"}"}]; // Categories [{"ID":1,"TypeID":1,"ParentID":0,"Name":"Prin

我正在调用两个Web API。第一个api类型中的每个值都有一个
ID
,需要使用该ID来过滤属于类别的第二个api。JSON的
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"}]

首先,您必须存储selectedTypeID,该ID将用于过滤另一个数组,然后才能调用第二个数组

辛塔克斯:

$filter('filter')(array, expression, comparator)
e、 g:


首先,您必须存储selectedTypeID,该ID将用于过滤另一个数组,然后才能调用第二个数组

辛塔克斯:

$filter('filter')(array, expression, comparator)
e、 g:


我想你是在问:*如何根据另一个
select
输入中的选择动态填充
select
输入

我想你可以走两条路。如果总数据不多(如
类别
),您可以对第二组数据使用
过滤器

您可以在HTML或控制器中执行此操作

<!-- HTML Page -->
<select>
  <option ng-repeat="value in values | filter..." value=value>
</select>

// controller.js
values = ($filter('filter')(result.Values, {Id: $routeParams.Id}));

//controller.js
values=($filter('filter')(result.values,{Id:$routeParams.Id}));

如果有大量数据要过滤,请考虑延迟调用<代码>类别<代码> API,直到选择<代码>类型< /代码>。< /p>


如果看不到控制器/HTML等等,很难给出具体的答案,但我认为这会让你朝着正确的方向前进。

我想你问的是:*如何根据另一个
选择
输入中的选择动态填充
选择
输入

$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>
我想你可以走两条路。如果总数据不多(如
类别
),您可以对第二组数据使用
过滤器

您可以在HTML或控制器中执行此操作

<!-- HTML Page -->
<select>
  <option ng-repeat="value in values | filter..." value=value>
</select>

// controller.js
values = ($filter('filter')(result.Values, {Id: $routeParams.Id}));

//controller.js
values=($filter('filter')(result.values,{Id:$routeParams.Id}));

如果有大量数据要过滤,请考虑延迟调用<代码>类别<代码> API,直到选择<代码>类型< /代码>。< /p> 如果没有看到controller/HTML之类的东西,很难给出具体的答案,但我认为这会让您朝着正确的方向前进。

$scope.countries=CustomerService.getCountry();
$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>
$scope.getCountryState=函数(){ $scope.sates=CustomerService.getCountryState($scope.customer.Country); $scope.cities=[]; }; --选择州-- --选择城市--
$scope.countries=CustomerService.getCountry();
$scope.getCountryState=函数(){
$scope.sates=CustomerService.getCountryState($scope.customer.Country);
$scope.cities=[];
};
--选择州--
--选择城市--

感谢您的回复。当我尝试angular$filter时,它几乎将我需要的信息排序到顶部,但没有创建仅包含这些值的select。嗯,这个$filter将返回一个仅包含筛选值的数组,您是否尝试将此数组设置为select值?我是否将Type中的值传递到我的控制器中,然后运行另一个函数根据类别数组检查该ID,并将该数组传递给select?谢谢您的回答。当我尝试angular$filter时,它几乎将我需要的信息排序到顶部,但没有创建仅包含这些值的select。嗯,这个$filter将返回一个仅包含筛选值的数组,您是否尝试将此数组设置为select值?我是否将Type中的值传递到我的控制器中,然后运行另一个函数根据类别数组检查该ID,并将该数组传递给select?谢谢您的响应。在类型选择中,我放置了一个ng更改,并从控制器调用了一个函数,该函数将该值设置为$scope.ID,并将其放置在类别选择的过滤器上。这是否与您在示例中尝试执行的操作一致?这样做是根据该ID对值进行排序,但其他值仍然存在。感谢您的响应。在类型选择中,我放置了一个ng更改,并从控制器调用了一个函数,该函数将该值设置为$scope.ID,并将其放置在类别选择的过滤器上。这是否与您在示例中尝试执行的操作一致?这样做是根据该ID对值进行排序,但其他值仍然存在。