1 回答
TA贡献1784条经验 获得超7个赞
好的,让我们用一个交互式代码片段来试试吧:
var props = {
"41": {
"citys_id": "41",
"citys_name": "Kocaeli",
"sub_citys": {
"505": {
"subcity_id": "505",
"subcity_name": "İzmit",
"subcity_city_id": "41",
"wtype": {
"1": {
"wtype_id": "1",
"wtype_name": "Yemek",
"wtype_icon": "http://icons.iconarchive.com/icons/dtafalonso/android-lollipop/32/Phone-icon.png",
"locations": [{
"loc_id": "13",
"loc_type": "1",
"loc_name": "With Beyond Bilişim",
"loc_number": "05322510292",
"loc_pazartesi": "1",
"loc_sali": "1",
"loc_carsamba": "1",
"loc_persembe": "1",
"loc_cuma": "1",
"loc_cumartesi": "0",
"loc_pazar": "1",
"loc_open": "1100",
"loc_close": "1400",
"loc_city": "41",
"loc_subcity": "505",
"loc_adress": "Çukurbağ Mahallesi, Molla Raşit Sokak, Numara: 14",
"loc_tarif": "Oradan çıkınca sola doğru dönüp devam edeceğiz",
"loc_lat": "41.0710419",
"loc_lng": "29.0127192"
}]
},
"3": {
"wtype_id": "3",
"wtype_name": "Eczane",
"wtype_icon": "https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png",
"locations": [{
"loc_id": "14",
"loc_type": "3",
"loc_name": "a",
"loc_number": "b",
"loc_pazartesi": "0",
"loc_sali": "0",
"loc_carsamba": "0",
"loc_persembe": "0",
"loc_cuma": "1",
"loc_cumartesi": "0",
"loc_pazar": "0",
"loc_open": "800",
"loc_close": "1200",
"loc_city": "41",
"loc_subcity": "505",
"loc_adress": "asd",
"loc_tarif": "asda",
"loc_lat": "40.5880381636505",
"loc_lng": "30.481870596093742"
}]
}
}
}
}
}
}
jQuery.each(props, function(key, value) {
$.each(value.sub_citys, function(key2, value2) {
$.each(value2.wtype, function(key3, value3) {
$.each(value3.locations, function(key4, value4) {
var Location = {
coords: {
lat: parseFloat(value4.loc_lat),
lng: parseFloat(value4.loc_lng)
},
iconImage: value3.wtype_icon,
content: '<div style="text-align:center;"><h5>' + value4.loc_name + '</h5><a>' + value4.loc_adress + '</a><br/><small>' + value4.loc_tarif + '</small><hr/>'
}
console.log(Location)
})
})
})
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
由于您的功能尚未完成,我选择暂时只记录该Location对象。
我还不确定要回答的是,“我的数组”包含比“我的对象”(又名props)更多的元素。值应该是null?保持原样?
添加回答
举报