如何从多个选择框中获取一系列选择值?

时间:2014-08-04 19:31:08

标签: angularjs select html-table angularjs-ng-change

我正在尝试获取表中动态生成的选择框的值的数组。你怎么能得到这些值的数组或其他数据类型?

这是表格:

  <table>
    <thead>
      <tr>
        <th>Personal Action Field(from Infor-Lawson)</th>
        <th>Form Fields</th>
      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="action in actionFields">
        <th>{{action.actionParam}} </th>
        <th>
          <select ng-model="name" ng-options="item.formField for item in formFields"></select>
          Currently selected: {{ name }}
        </th>
      </tr>
    </tbody>
  </table>
  <br><br>
  <button ng-click="lastPage()">Back</button> 
  <button ng-click="nextPage(); mapValues()">Next</button> 

这是控制器:

function FormActionFieldController($scope, $http, $rootScope) {
  $rootScope.data = null;

  $http.get('http://localhost:82/rs/transformTrigger/formFields')
    .success(function (data, status, headers, config) {
      $rootScope.formFields = data;
  })
  .error(function (data, status, headers, config) {
     //  Do some error handling here
    alert('error FormActionFieldController');
  });
  $rootScope.getFields=function(){  
    $scope.actionFields = null;
    $scope.httpData = '{"actionName":"'+$rootScope.actionTypeName+'"}';

  $http.post('http://localhost:82/rs/transformTrigger/lawsonFields', $scope.httpData)
      .success(function (data, status, headers, config) {
       $scope.actionFields = data;
  })
  .error(function (data, status, headers, config) {
      //  Do some error handling here
  });
  }
  $scope.nextPage=function(){
      $rootScope.page3=false;
      $rootScope.page4=true;
  }
  $scope.lastPage=function(){
    $rootScope.page3=false;
    $rootScope.page2=true;
  }
 $scope.mapValues=function(){
    $rootScope.submitArray = $rootScope.formFields;
    alert($rootScope.submitArray);

  }
 }

1 个答案:

答案 0 :(得分:0)

你可以使用$ index

<select ng-model="name[$index]" ng-options="item.formField for item in formFields"></select>

通过这种方式,您可以获得一系列选定值