简体   繁体   English

访问数组内对象的值

[英]Access to value of object inside array

I have a complicated response from an http request as shown below: 我收到来自http请求的复杂响应,如下所示:

"rates": [
            {
                "non_refundable": false,
                "no_of_rooms": 1,
                "includes_wifi": false,
                "includes_boarding": true,
                "has_promotions": true,
                "group_code": "xgirbylkwb6xtg",
                "currency": "INR",
                "cancellation_policy": {
                    "under_cancellation": false,
                    "details": [
                        {
                            "from": "2016-12-25T00:00:00",
                            "flat_fee": 20309.01,
                            "currency": "INR"
                        }
                    ],
                    "cancel_by_date": "2016-12-24T00:00:00",
                    "amount_type": "value"
                }
           }
      ]

Rates length is between 6-20 inside another array with length of around 200. The "cancellation_policy" shows up only if "non_refundable": false . 率长度为6-20之间绕200的长度的另一数组内"cancellation_policy"示出了仅当"non_refundable": false

How I can access "from": "2016-12-25T00:00:00" and change the format with Moment JS and how I can access "flat_fee": 20309.01 ? 如何访问"flat_fee": 20309.01 "from": "2016-12-25T00:00:00"并使用Moment JS更改格式以及如何访问"flat_fee": 20309.01

I tried using angular.forEach already but it defines only the value of last array . 我已经尝试使用angular.forEach但是它仅定义了last array的值。

I tried this already: 我已经尝试过了:

 if ($scope.data[i].rates[j].non_refundable == false) {
for (var d = $scope.data[i].rates[j].cancellation_policy.details.length - 1; d >= 0; d--) {

But I had no success. 但是我没有成功。

ps: The value should show on $mdDialog ps:该值应显示在$mdDialog

You don't need to loop under details, just do it like this : 您无需在细节下循环,只需这样做:

var startdate = $scope.data[i].rates[j].cancellation_policy.details[0].from;
var new_date = moment(startdate).format('MMMM Do YYYY, h:mm:ss a');
var other = $scope.data[i].rates[j].cancellation_policy.details[0].flat_fee;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM