【发布时间】:2015-03-11 10:04:04
【问题描述】:
我正在使用 ng-repeat 重复一个表单。重复是创造一个新的形式。 我想通过单击提交所有表单数据。我无法找到如何在数组中分配多个值。
这是我的表格:
<div id="check" ng-repeat="screen in screens">
<input type="hidden" name="scrnid" ng-model="screen.scrnid" value="{{ screen.scrnid }}" />
<label>Name:</label>
<input type="text" ng-model="screen.bdayname" placeholder="Name" ng-required/>
<label>Date:</label>
<input type="date" ng-model="screen.bdaydate" placeholder="Date" ng-required/>
<br/>
</div>
<button class="btn" type="submit" ng-click="newBirthday()">Save</button>
</div>
<div class="container">
<input type="button" class="btn" ng-click="createScreen()" /><i class="icon-plus"></i>Add
</div>
它是我的控制器
app.controller('main', function($scope){
$scope.screens = [{scrnid: "1"}];
$scope.scrnid = 1;
$scope.createScreen = function()
{
$scope.screens.push({scrnid: "" + ($scope.screens.length + 1)});
};
$scope.bdays = [];
// Create the function to push the data into the "bdays" array
$scope.newBirthday = function(){
$scope.bdays.push($scope.screens.length); // how to push mutiple records in array dynamically
$scope.screen.bdayname = '';
$scope.screen.bdaydate = '';
};
});
我们将不胜感激...
【问题讨论】:
-
assign multiple values in array,这多个值是什么? -
$scope.bdays.push() 在这个数组中如果我想发送多个值,我会这样做: $scope.bdays.push([ {'name': 'name1' }, {'name': 'name2'} ]);这是 angularjs 的做法。但是我应该怎么做才能将重复的html表单中的值插入到这个数组中......
标签: javascript jquery angularjs angularjs-ng-model