查询 JSON 对象

Query a JSON Object?

本文关键字:对象 JSON 查询      更新时间:2023-09-26

我正在尝试使用下划线库查询 JSON 对象,但我无法查询以下 JSON 结构。'$scope.conScopeFreqStartDates' 变量具有以下 JSON 值。

我正在传递"频率代码输入"值在下划线脚本中有"Y"。

    [
       {
          "consolidationScopeId": 4008,
          "consolidationScopeCode": "S",
          "consolidationScopeLabel": "Individual",
          "frequencies": [
             {
                "frequencyCode": "M",
                "frequencyLabel": "Monthly",
                "startDates": [
                   "2016-01-31",
                   "2016-02-28"
                ]
             },
             {
                "frequencyCode": "Y",
                "frequencyLabel": "Annual",
                "startDates": [
                   "2016-12-31",
                   "2017-12-31"
                ]
             }
          ]
       }]

我正在尝试从 JSON 对象获取开始日期,

控制器

var startDates = _.findWhere($scope.conScopeFreqStartDates, {
            'frequencies.frequencyCode': frequencyCodeInput
        }).startDates;
        $scope.startDates = startDates;

"开始日期"对于我的上述代码是未定义的。

我会在对象上的频率数组上调用 _.findWhere,而不是整个对象

var startDates = _.findWhere($scope.conScopeFreqStartDates.frequencies, {
            'frequencyCode': frequencyCodeInput
        }).startDates;
        $scope.startDates = startDates;