【问题标题】:sending multiple array in multiple array in Angular js在Angular js中的多个数组中发送多个数组
【发布时间】:2016-09-06 09:22:31
【问题描述】:

如何在 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;
                }

            });  */

};

现在我只需要用angular js发送这个数据格式,请建议

这就是我通过“硬代码”在 Angular 中所做的事情,我需要在 Angular js 中发送这些数据,我该怎么做?

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

【问题讨论】:

  • 你想从 angularjs 发送数据还是想用 angularjs 显示这些数据?
  • 相应地发送和获取
  • 你想在 HTML 中也显示这些数据吗?
  • 是的......我也想获取并显示它的html
  • 你应该使用$http服务DOC

标签: angularjs arrays json angularjs-scope


【解决方案1】:

有一个数组

$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);

【讨论】:

  • 它只返回 1
  • 再次返回 1
  • 发送整个数组,返回1表示..!告诉我你如何从 Js 调用 API。
  • 这只是我在控制台上打印得到的数组长度而不是值$scope.schedule = []; $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 = { "Schedule":$scope.schedule.push($scope.week) // here schedule.push is an array } console.log(angular.toJson(dataParam));
  • 把这个 "Schedule":angular.toJson($scope.schedule.push($scope.week)) 改成 "Schedule":angular.toJson($scope.schedule)
猜你喜欢
  • 2017-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-13
  • 1970-01-01
  • 1970-01-01
  • 2019-07-06
  • 1970-01-01
相关资源
最近更新 更多