我有一个复杂的数据结构,其中包含嵌套数组,我需要使用不区分大小写的搜索方法查找带有字符串值的元素。
由于lodash具有执行嵌套查询的简单语法,因此我已开始使用它 - 它很好用,但是搜索区分大小写。
我想要查找一个"address_components"元素,其"types"值为'route',并且"long_name"值等于名为'targetStreet'的参数。
以下是我目前使用的lodash代码:
由于lodash具有执行嵌套查询的简单语法,因此我已开始使用它 - 它很好用,但是搜索区分大小写。
我想要查找一个"address_components"元素,其"types"值为'route',并且"long_name"值等于名为'targetStreet'的参数。
以下是我目前使用的lodash代码:
var result = _.find(geocodeResult,
{
'address_components': [
{
types: ['route'],
'long_name': targetStreet
}
]
});
问题: 如何使“long_name”属性的匹配不区分大小写?
下面是“geocodeResult”数据结构的示例(实际上是Google Geocoding Result对象)。
请注意,此数据结构是动态的... Google将返回它能找到的最具体的结果,但如果无法找到街道的匹配项,则不会返回街道组件,例如“address_components”中的“types”数组具有非确定性值。
[
{
"address_components": [
{
"long_name": "V&a Lane",
"short_name": "V&a Ln",
"types": [
"route"
]
},
{
"long_name": "Coonawarra",
"short_name": "Coonawarra",
"types": [
"locality",
"political"
]
},
{
"long_name": "Wattle Range Council",
"short_name": "Wattle Range",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "South Australia",
"short_name": "SA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Australia",
"short_name": "AU",
"types": [
"country",
"political"
]
},
{
"long_name": "5263",
"short_name": "5263",
"types": [
"postal_code"
]
}
],
"formatted_address": "V&a Ln, Coonawarra SA 5263, Australia",
"geometry": {
"bounds": {
"south": -37.3238134,
"west": 140.8154452,
"north": -37.3228868,
"east": 140.97295129999998
},
"location": {
"lat": -37.3233904,
"lng": 140.89510410000003
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"south": -37.3246990802915,
"west": 140.8154452,
"north": -37.3220011197085,
"east": 140.97295129999998
}
},
"partial_match": true,
"place_id": "EiVWJmEgTG4sIENvb25hd2FycmEgU0EgNTI2MywgQXVzdHJhbGlh",
"types": [
"route"
]
},
{
"address_components": [
{
"long_name": "V&a Lane",
"short_name": "V&a Ln",
"types": [
"route"
]
},
{
"long_name": "Coonawarra",
"short_name": "Coonawarra",
"types": [
"locality",
"political"
]
},
{
"long_name": "Wattle Range Council",
"short_name": "Wattle Range",
"types": [
"administrative_area_level_2",
"political"
]
},
{
"long_name": "South Australia",
"short_name": "SA",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "Australia",
"short_name": "AU",
"types": [
"country",
"political"
]
},
{
"long_name": "5263",
"short_name": "5263",
"types": [
"postal_code"
]
}
],
"formatted_address": "V&a Ln, Coonawarra SA 5263, Australia",
"geometry": {
"bounds": {
"south": -37.3238134,
"west": 140.8154452,
"north": -37.3228868,
"east": 140.97295129999998
},
"location": {
"lat": -37.3233904,
"lng": 140.89510410000003
},
"location_type": "GEOMETRIC_CENTER",
"viewport": {
"south": -37.3246990802915,
"west": 140.8154452,
"north": -37.3220011197085,
"east": 140.97295129999998
}
},
"partial_match": true,
"place_id": "EiVWJmEgTG4sIENvb25hd2FycmEgU0EgNTI2MywgQXVzdHJhbGlh",
"types": [
"route"
]
}
]