代码更改了foreach循环angularjs中数组的长度

时间:2016-02-06 05:43:23

标签: javascript angularjs

数组的长度是3来自server.lenging下面代码中的数据值当我评论b.days的条件部分$ scope.bookingdetails的长度是好的但当我使用这个长度$ scope.bookingdetails变成只有1。 请帮帮我

谢谢

$http.post('bookings/getdetails/', datatosend).then
            (function (response) {
                console.log(response);
                if (response.data.response == 1) {
                    $scope.receivings = response.data.receivings;
                    $scope.bookingdetails = angular.copy(response.data.bookingdetails);
                    angular.forEach($scope.bookingdetails, function (b) {
                        var t = b.arrival.split(/[- :]/);
                        var d = new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]);
                        b.arrival = d;
                        var t = b.departure.split(/[- :]/);
                        var d = new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]);
                        b.departure = d;

                        var t = b.checkintime.split(/[- :]/);
                        var d = new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]);
                        b.checkintime = d;


                        if (b.checkouttime != null) {
                            var t = b.checkouttime.split(/[- :]/);
                            var d = new Date(t[0], t[1] - 1, t[2], t[3], t[4], t[5]);
                            b.checkouttime = d;
                        }

                        var tdy = parseInt(b.days);
                            if (parseInt(b.diffhours) > 1) {
                                tdy = parseInt(tdy) + 1;
                            }
                            else if (parseInt(b.diffhours) == 0) {
                                if (parseInt(b.days) == 0) {
                                    tdy = 1;
                                }
                            }


                        var daysamount = parseInt(tdy) * parseInt(b.amount);
                        console.log('d am : ' + daysamount + ' days : ' + tdy + ' amt : ' + b.amount);
                        var extrapersoncharges = 0;
                        if (b.extraperson != 0) {
                            extrapersoncharges = parseInt(tdy) * (parseInt(b.extrapersoncharges) * parseInt(b.extraperson));
                        }
                        var roomreceivings = 0;
                        var roomservices = 0;

                        angular.forEach($scope.receivings, function (r) {
                            if (r.booking_id == b.booking_id) {
                                roomreceivings = roomreceivings + r.amount;
                            }
                        });
                        angular.forEach($scope.services, function (s) {
                            if (s.booking_id == b.booking_id) {
                                roomservices = roomservices + (s.amount * s.times);
                            }
                        });
                        roomreceivings = roomreceivings + b.advance;
                        var finalpayable = parseInt(daysamount) + parseInt(extrapersoncharges) + parseInt(roomservices);
                        if (parseInt(roomreceivings) > parseInt(finalpayable)) {
                            b.finalrefundable = parseInt(roomreceivings) - parseInt(finalpayable);
                            b.finalreceivable = 0;
                        }
                        else
                        {
                            b.finalrefundable = 0;
                            b.finalreceivable = parseInt(finalpayable) - parseInt(roomreceivings);
                        }
                        $scope.globalcharges = parseInt($scope.globalcharges) + parseInt(finalpayable);
                        $scope.globalreceived = parseInt($scope.globalreceived) + parseInt(roomreceivings);
                        console.log('print');
                    });


                    if ($scope.globalcharges > $scope.globalreceived) {
                        $scope.finalreceivable = parseInt($scope.globalcharges) - parseInt($scope.globalreceived);
                    }
                    else
                    {
                        $scope.finalreceivable = 0;
                    }
                    $scope.customerdetails = response.data.customerdetails;
                    //$scope.getRooms();
                    $scope.selectedRoom = $scope.globalRoom.room_id;//$scope.bookingdetails[0].room_id;
                    $scope.services = response.data.services;
                }
            }, function (response) {
                alert('Error loading');
            });

0 个答案:

没有答案