我试图使用下划线库查询JSON对象,但我无法查询下面的JSON结构。 ' $ scope.conScopeFreqStartDates'变量具有以下JSON值。
我正在传递' frequencyCodeInput'价值有' 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对象中获取startDates,
控制器
var startDates = _.findWhere($scope.conScopeFreqStartDates, {
'frequencies.frequencyCode': frequencyCodeInput
}).startDates;
$scope.startDates = startDates;
' startDates'我的上述代码未定义。
答案 0 :(得分:1)
我会在对象的频率数组上调用_.findWhere,而不是整个对象
var startDates = _.findWhere($scope.conScopeFreqStartDates.frequencies, {
'frequencyCode': frequencyCodeInput
}).startDates;
$scope.startDates = startDates;