Angularjs 如何将嵌套的from中的输入字段数据循环到angular js中的数组?
实际上,我需要在表单验证之后以这种格式显示数组中的数据。请任何人帮帮我,我是新手Angularjs 如何将嵌套的from中的输入字段数据循环到angular js中的数组?,angularjs,Angularjs,实际上,我需要在表单验证之后以这种格式显示数组中的数据。请任何人帮帮我,我是新手 $scope.newuser=[ { "EmployeeID": "A123", "FullName": "phantommm", "UserRegistrationDate": "2015-07-10T00:00:00", "LastActiveDate": "2015-07-10T00:00:00", "UserProjects": [ {
$scope.newuser=[
{
"EmployeeID": "A123",
"FullName": "phantommm",
"UserRegistrationDate": "2015-07-10T00:00:00",
"LastActiveDate": "2015-07-10T00:00:00",
"UserProjects": [
{
"UserID": 1,
"ProjectID": 1,
"ProjectRoleID": 2,
"IsAccepted": true
},
{
"UserID": 1,
"ProjectID": 2,
"ProjectRoleID": 3,
"IsAccepted": true
}
]
},
{
"EmployeeID": "A123",
"FullName": "phantommm",
"UserRegistrationDate": "2015-07-10T00:00:00",
"LastActiveDate": "2015-07-10T00:00:00",
"UserProjects": [
{
"UserID": 2,
"ProjectID": 1,
"ProjectRoleID": 2,
"IsAccepted": true
}
]
}
]
但我得到的数据是这种格式的
$scope.newuser=[
{
"EmployeeID": "A123",
"FullName": "phantommm",
"UserRegistrationDate": "2015-07-10T00:00:00",
"LastActiveDate": "2015-07-10T00:00:00",
"UserID": 1,
"ProjectID": 1,
"ProjectRoleID": 2,
"IsAccepted": true
},
{
"EmployeeID": "A12345",
"FullName": "phantommm123",
"UserRegistrationDate": "2015-07-10T00:00:00",
"LastActiveDate": "2015-07-10T00:00:00",
"UserID": 2,
"ProjectID": 1,
"ProjectRoleID": 3,
"IsAccepted": true
}
]
我用这个代码从表单中获取数据
myapp.controller('mainController', function ($scope) {
$scope.submitForm = function() {
$scope.newuser = [];
$scope.submitted = true;
$scope.counter = 1;
$scope.counter++;
if ($scope.userForm.$valid) {
$scope.newuser.push({
UserID : $scope.counter,
EmployeeID : $scope.user.employeeid,
FullName : $scope.user.fname,
UserPassword : $scope.user.confirmPassword,
EmailID : $scope.user.email,
Mobile : $scope.user.phone,
SecurityQuestionID : $scope.user.secutyqquestn,
SecurityAnswer : $scope.user.secutyanswer,
id : $scope.counter,
ctpjct : $scope.user.curntpjct,
pos : $scope.user.positio
})
alert('Registration Succesfully Completed');
} else {
alert('Invalid Fields')
}
})}); 使用这种结构是正常的,因为您将所有数据推送到同一级别。。您应该有:$scope.user.userprojects.push({“UserID”:$scope.counter,“ProjectID”:$scope.user.currentpjct,“ProjectRoleID”:$scope.user.role,“IsAccepted”:$scope.user.status})非常感谢您。它正在工作…@MayKit你正在使用这个结构是正常的,因为你把所有的数据都推到了同一个级别。。您应该有:$scope.user.userprojects.push({“UserID”:$scope.counter,“ProjectID”:$scope.user.currentpjct,“ProjectRoleID”:$scope.user.role,“IsAccepted”:$scope.user.status})非常感谢您。它起作用了…@MayK