4

我使用 AngularJS 创建了两个下拉菜单,并通过控制器在其中添加了数据。当第一个下拉列表发生更改时,我想更改第二个下拉列表值。

我创建了示例,但是当我更改第一个下拉列表的值时;第二个下拉值不会改变。

4

1 回答 1

11

更新的 HTML:

<div ng-controller="exerciseTypeCtrl">

<ul data-role="listview" data-inset="true" >
<li>
    <select id="exerciseSuperCategory" data-role="listview" ng-options="catagory as catagory.text for catagory in catagories.cast " ng-model="itemsuper" ng-change="changeData()">
    </select>
</li>
</ul>       
<ul data-role="listview" data-inset="true">
<li>
    <select data-role="listview" ng-options="type as type.text for type in types.cast " ng-model="item1" ng-change="update()">

    </select>
</li>
</ul>

更新的控制器:

myApp.controller('exerciseTypeCtrl',function($scope,indoors,outdoors,setNulls, catagories){

$scope.catagories = catagories;
$scope.types = setNulls;
$scope.changeData = function() {
    //console.log($scope.itemsuper);

    if($scope.itemsuper.text == "Indoor") {
        $scope.types = indoors;
    } else if($scope.itemsuper.text == "Outdoor") {
        $scope.types = outdoors;
    } else {
        $scope.types = setNulls;
    }
 }
});

更新示例

于 2013-09-21T13:18:51.527 回答