后台返回的对象如下
{
"result": [
{
"cityAndPrefecture": [
{
"city": "滨海新区",
"prefecture": [
"全市",
"天津滨海旅游区",
"天津东疆海水浴场"
]
}
],
"province": "天津市"
},
{
"cityAndPrefecture": [
{
"city": "东营",
"prefecture": []
},
{
"city": "威海",
"prefecture": []
},
{
"city": "日照",
"prefecture": [
"全市",
"日照桃花岛"
]
},
{
"city": "滨州",
"prefecture": []
},
{
"city": "潍坊",
"prefecture": [
"全市",
"潍坊度假区"
]
},
{
"city": "烟台",
"prefecture": [
"全市",
"海阳万米海滩",
"金沙滩海水浴场(烟台)",
"屺坶岛"
]
},
{
"city": "青岛",
"prefecture": [
"全市",
"第一海水浴场",
"第六海水浴场",
"石老人海水浴场",
"金沙滩海水浴场(青岛)"
]
}
],
"province": "山东省"
},
{
"cityAndPrefecture": [
{
"city": "唐山",
"prefecture": []
},
{
"city": "沧州",
"prefecture": []
},
{
"city": "秦皇岛",
"prefecture": [
"全市",
"北戴河老虎石浴场",
"南戴河浴场",
"东山浴场",
"西浴场",
"北戴河旅游区"
]
}
],
"province": "河北省"
},
{
"cityAndPrefecture": [
{
"city": "丹东",
"prefecture": []
},
{
"city": "大连",
"prefecture": [
"全市",
"棒棰岛浴场",
"付家庄浴场",
"星海浴场",
"夏家河浴场",
"泊石湾",
"金石滩",
"仙浴湾",
"大黑石",
"塔河湾"
]
},
{
"city": "盘锦",
"prefecture": []
},
{
"city": "营口",
"prefecture": []
},
{
"city": "葫芦岛",
"prefecture": []
},
{
"city": "锦州",
"prefecture": []
}
],
"province": "辽宁省"
}
],
"success": true
}
传入一个值,如果这个值是city的值 就返回 city province 的索引值 传入是prefecture的值 就返回 prefecture city province的值
[0,1] 或者 [0,2,3]这种
因为三层数据,是固定的,可以直接为每层写一个查找方法,把查找的结果拼接起来就可以了
但实际上,每一层的查找方法是可以抽象出共性的,只是取值的 name 和取子列表的 children 名称不同而已。此外,还有最后一层是直接在字符串数组中查找,抽象出来之后可以这样写
调用方式差不多