在Angular js中以多个数组发送多个数组

时间:2016-09-06 09:22:31

标签: angularjs arrays json angularjs-scope

如何在AngularJS中发送此数据。 (它是多个数组中需要发送一个对象的多个数组)

[{
"working_day":"sunday",
"from_time":{"hour":"9","min":"30"},
"to_time":{"hour":"6","min":"30"}
},{
"working_day":"monday",
"from_time":{"hour":"9","min":"30"},
"to_time":{"hour":"6","min":"30"}... and so on for other week days
}]

我正在尝试在API中发送这样的数据,而且我是AngularJs的新手,所以请告诉我如何在运行时通过HTML创建这些数据?

            $scope.schedule = []; // Hard coded value
            $scope.week = {};
            $scope.week.working_day = "Sunday";
            $scope.week.from_time = {};
            $scope.week.from_time.min = "10:00";
            $scope.week.from_time.max = "5:00";
            $scope.week.to_time = {};
            $scope.week.to_time.min = "2:10";
            $scope.week.to_time.max = "8:00";

    var dataParam =  {
                        "prefix":$scope.data1.prefix,
                        "first_name":$scope.data1.first_name,
                        "password":$scope.data1.password,
                        "last_name":$scope.data1.last_name,
                        "email_id":$scope.data1.email_id,
                        "mobile_number":$scope.data1.mobile_number,
                        "roleCode":[$scope.data1.roleCode],
                        "role":[$scope.data1.role],
                        "Schedule":angular.toJson($scope.schedule.push($scope.week))

                      }
 console.log(angular.toJson(dataParam));
            /* $http({
            url:  "/here",
            method: "POST",
            headers :{'Content-Type': 'application/json','Accept': 'application/json' },
            data: dataParam
            }) .success(function(response) {
                if(response.status_code=="success")
                {
                    $scope.successmsg = response.status_message;

            console.log(angular.toJson(response));
            $state.go('dashboard.setting.user', {'user': $scope.viewUser});
                }
                else {

              $scope.successmsg = response.status_code;
                }

            });  */

};

现在我只需要使用角度js发送此数据格式,请建议

这就是我在角色中所做的事情"硬编码"我需要以角度js发送这些数据,我该怎么做?

现在请帮我使用angular的html代码将用户的硬编码值发送到运行时值

1 个答案:

答案 0 :(得分:0)

有阵列

$scope.schedule = [];

使用Json密钥创建对象

$scope.week = {};
$scope.week.working_day = "";
$scope.week.from_time = {};
$scope.week.from_time.min = "";
$scope.week.from_time.max = "";
$scope.week.to_time = {};
$scope.week.to_time.min = "";
$scope.week.to_time.max = "";

将其推入数组

$scope.schedule.push($scope.week);