嵌套并动态创建ng-model到ng-repeat

时间:2014-06-11 13:36:33

标签: javascript angularjs

我知道有很多关于这个问题的问题,但我无法解决我的问题。

我的项目的最终结果是创建一个xml文件。

为此,我需要让用户选择一个根节点,并根据他的选择向我的数据库发送请求,以检索此根节点的可能子节点。然后他选择了他想要的孩子,并且我发送了另一个请求来检索这个节点的可能孩子,依此类推,直到我到达一片叶子。

所以我需要动态显示下拉列表。但是为了能够创建xml我需要保存他所做的每一个选择,所以我需要将选定的节点保持在单独的ng模型中。

基于其他问题及其答案,我试过这个:

html:

    <select ng-model='selectedstandard' ng-options='item for item in standard' ng-change="getTypes()">
        <option value="">select standard</option>
    </select>

    <select ng-model='selectedstandard[$index]' ng-options='item for item in standard' ng-change="getTypes()" ng-repeat="node in nodes">
        <option value="">select standard</option>
    </select>

maincontroller.js:

$scope.nodes=[];
$scope.getTypes = function(){
  $scope.types = $http({
     method: 'GET',
     url: 'http://localhost:8080/hello/types',
     headers: {'Content-Type': 'application/json', 'standard' : $scope.selectedstandard}
     }).success(function (data) 
     {
         $scope.types=data;
         var i=0;
         var simpleTypesTemp = JSON.parse(JSON.stringify($scope.types));
         for(var ty in $scope.types){
         var valuetab=($scope.types[ty]).split(":");
         simpleTypesTemp[ty]= valuetab[0]+":...:"+valuetab[(valuetab.length)-1];
     }
 });
 if($index){
    $scope.nodes.push($scope.selectedstandard[$index]);
 }
 else{
    $scope.nodes.push($scope.selectedstandard);
  }
  $scope.getNameSpace();
}

但是我收到错误告诉我$ index未定义。

我猜两个名为selectedstandard和selectedstandard [$ index]的ng模型不是一个好主意,但我需要以某种方式初始化循环。

0 个答案:

没有答案
相关问题