-
Notifications
You must be signed in to change notification settings - Fork 0
/
getJdArea.js
67 lines (66 loc) · 1.37 KB
/
getJdArea.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var areaData = [],
getProvince = function(){
$.ajax({
url:'/address/getProvinces.action',
dataType:'json',
success:function(data){
var pIndex = 0;
for(var key in data){
areaData.push({
id:key,
parentId:'0',
name:data[key + ''],
children:[]
});
getCity(key,pIndex);
pIndex ++;
}
}
})
},
getCity = function(pId,pIndex){
$.ajax({
url:'/address/getCitys.action',
dataType:'json',
data:{
provinceId:pId
},
success:function(data){
var cityData = [],cIndex = 0;
for(var key in data){
cityData.push({
id:key,
parentId:pId,
name:data[key + ''],
children:[]
});
getCounty(key,pIndex,cIndex);
cIndex ++;
}
cityData.length&&(areaData[pIndex].children = cityData);
}
})
},getCounty = function(cId,pIndex,cIndex){
$.ajax({
url:'/address/getCountys.action',
dataType:'json',
data:{
cityId:cId
},
success:function(data){
var countyData = [];
for(var key in data){
countyData.push({
id:key,
parentId:cId,
name:data[key + '']
})
}
countyData.length&&(areaData[pIndex].children[cIndex].children = countyData);
}
})
};
getProvince();
setTimeout(function(){
console.log(JSON.stringify(areaData));
},20000);//延时时间自己定