【发布时间】:2014-09-27 08:49:53
【问题描述】:
我正在尝试获取表格中动态生成的选择框的值数组。您如何获得这些值的数组或其他数据类型?
这是表格:
<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);
}
}
【问题讨论】:
-
什么看起来像一个formField?如果您有 id 或名称,则可以使用 ng-model=datas[name] 存储数据。使用它,您将获得一个包含选定数据的对象,您可以对其进行迭代以获得所需的数组。
标签: angularjs select html-table angularjs-ng-change