如何将嵌套的输入字段数据循环到角度js中的数组?

时间:2015-11-06 13:42:37

标签: angularjs

实际上我需要在表单验证后以这种格式显示数组中的数据。请任何人帮助我,我是棱角分明的新手。

$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')
}

};
  });

0 个答案:

没有答案