回答編集履歴
1
ソースはできれば書きたくない
test
CHANGED
@@ -1,93 +1 @@
|
|
1
|
-
```ここに言語を入力
|
2
|
-
main()
|
3
|
-
|
4
|
-
function main() {
|
5
|
-
$.ajax({
|
6
|
-
url: "map.xml",
|
7
|
-
success: function(result) {
|
8
|
-
//データ一括取得
|
9
|
-
|
1
|
+
自己解決のため、問題なし
|
10
|
-
var data1 = []
|
11
|
-
var data2 = []
|
12
|
-
var data3 = []
|
13
|
-
$(result).find("result item").each(function(index, item) {
|
14
|
-
var id = $(item).find("id").text();
|
15
|
-
var type_number = $(item).find("type_number").text();
|
16
|
-
var sort_number = $(item).find("sort_number").text();
|
17
|
-
var area_number = $(item).find("area_number").text();
|
18
|
-
var picture = $(item).find('img').text();
|
19
|
-
var title = $(item).find('title').text();
|
20
|
-
data[index] = [id, type_number, sort_number, area_number, picture, title]
|
21
|
-
})
|
22
|
-
// 用途別IDの配列に分割
|
23
|
-
for (index in data) {
|
24
|
-
if (data[index][1] === "1") {
|
25
|
-
data1[index] = data[index]
|
26
|
-
}
|
27
|
-
else if (data[index][1] === "2") {
|
28
|
-
data2[index] = data[index]
|
29
|
-
}
|
30
|
-
else if (data[index][1] === "3") {
|
31
|
-
data3[index] = data[index]
|
32
|
-
}
|
33
|
-
}
|
34
|
-
//並び替え処理
|
35
|
-
sort(data1)
|
36
|
-
sort(data2)
|
37
|
-
sort(data3)
|
38
|
-
function sort(array) {
|
39
|
-
array.sort(function(a, b) {
|
40
|
-
if (Number(b[2]) > Number(a[2])) {
|
41
|
-
return -1;
|
42
|
-
}
|
43
|
-
else if (Number(b[2]) < Number(a[2])) {
|
44
|
-
return 1;
|
45
|
-
}
|
46
|
-
else {
|
47
|
-
return 0;
|
48
|
-
}
|
49
|
-
});
|
50
|
-
}
|
51
|
-
|
52
|
-
//HTML出力
|
53
|
-
for (index in data1) {
|
54
|
-
$(function() {
|
55
|
-
var inHtml = "<li class='list_view list_area" + data1[index][3] + "'>" +
|
56
|
-
"<a href='/ja/portfolio/detail.html?id=" + data1[index][0] + "'>" +
|
57
|
-
"<span class='portfolio-type-list__img' style='background-image: url("" + data1[index][4] + "")'></span>" +
|
58
|
-
"<p>" + data1[index][5] + "</p>" +
|
59
|
-
"</a>" +
|
60
|
-
+"</li>";
|
61
|
-
$('ul.portfolio-type-1.portfolio-type-1').append($(inHtml));
|
62
|
-
});
|
63
|
-
}
|
64
|
-
for (index in data2) {
|
65
|
-
$(function() {
|
66
|
-
var inHtml = "<li class='list_view list_area" + data2[index][3] + "'>" +
|
67
|
-
"<a href='/ja/portfolio/detail.html?id=" + data2[index][0] + "'>" +
|
68
|
-
"<span class='portfolio-type-list__img' style='background-image: url("" + data2[index][4] + "")'></span>" +
|
69
|
-
"<p>" + data2[index][5] + "</p>" +
|
70
|
-
"</a>" +
|
71
|
-
+"</li>";
|
72
|
-
$('ul.portfolio-type-2.portfolio-type-2').append($(inHtml));
|
73
|
-
});
|
74
|
-
}
|
75
|
-
for (index in data3) {
|
76
|
-
$(function() {
|
77
|
-
var inHtml = "<li class='list_view list_area" + data3[index][3] + "'>" +
|
78
|
-
"<a href='/ja/portfolio/detail.html?id=" + data3[index][0] + "'>" +
|
79
|
-
"<span class='portfolio-type-list__img' style='background-image: url("" + data3[index][4] + "")'></span>" +
|
80
|
-
"<p>" + data3[index][5] + "</p>" +
|
81
|
-
"</a>" +
|
82
|
-
+"</li>";
|
83
|
-
$('ul.portfolio-type-3.portfolio-type-3').append($(inHtml));
|
84
|
-
});
|
85
|
-
}
|
86
|
-
},
|
87
|
-
error: function(data) {
|
88
|
-
console.log(data);
|
89
|
-
}
|
90
|
-
});
|
91
|
-
}
|
92
|
-
|
93
|
-
```
|