-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.html
166 lines (154 loc) · 6.69 KB
/
main.html
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<html>
<head>
<title>导师评价</title>
<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<style>
</style>
</head>
<body>
<h1 class="mt-3 mb-5 text-center">导师评价信息</h1>
<div class="container mt-3">
<div class="row">
<div class="col col-4">
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="schoolcateSelector">选择学校类别</label>
</div>
<select class="custom-select" id="schoolcateSelector">
<option selected>选择学校类别</option>
</select>
</div>
</div>
<div class="col col-4">
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="universitySelector">选择学校</label>
</div>
<select class="custom-select" id="universitySelector">
<option selected>选择所在学校</option>
</select>
</div>
</div>
<div class="col col-4">
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="departmentSelector">选择院系</label>
</div>
<select class="custom-select" id="departmentSelector">
<option selected>选择所在院系</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col col-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="supervisorSelector">选择导师</label>
</div>
<select class="custom-select" id="supervisorSelector">
<option selected>选择姓名</option>
</select>
</div>
</div>
<div class="col col-6 mb-3 text-center">
<button type="button" class="btn btn-primary" style="width: 90%;" id="confirmBtn">确认</button>
</div>
</div>
<div class="descriptions">
</div>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="data.js"></script>
<script>
function getValuesInObjs(arr, key) {
var resultArr = new Array();
arr.forEach(function (obj) {
if (!resultArr.includes(obj[key])) {
resultArr.push(obj[key]);
}
});
return resultArr.sort(function (item1, item2) {
return item1.localeCompare(item2, 'zh');
});
}
function filterValuesInArray(arr, key, value) {
var resultArr = new Array();
arr.forEach(function (obj) {
if (obj[key] == value) {
resultArr.push(obj);
}
});
return resultArr;
}
function setSelectOptions(selector, options) {
selector.empty();
options.forEach(function (value, i) {
var option = new Option(value, i);
selector.append($(option));
//option.selected = true;
});
}
var schoolcate = $('#schoolcateSelector');
var university = $('#universitySelector');
var department = $('#departmentSelector');
var supervisor = $('#supervisorSelector');
var confirmBtn = $('#confirmBtn');
var contentDiv = $('.descriptions');
var schoolcates = getValuesInObjs(data, 'school_cate')
var universities = new Array();
var departments = new Array();
var supervisors = new Array();
var currentCt = '';
var currentUn = '';
var currentDp = '';
var currentSp = '';
schoolcate.change(function () {
currentCt = schoolcates[schoolcate.val()];
var thisData = filterValuesInArray(data, 'school_cate', currentCt);
universities = getValuesInObjs(thisData, 'university');
setSelectOptions(university, universities);
university.trigger('change');
});
university.change(function () {
currentUn = universities[university.val()];
var thisData = filterValuesInArray(data, 'university', currentUn);
departments = getValuesInObjs(thisData, 'department');
setSelectOptions(department, departments);
department.trigger('change');
});
department.change(function () {
currentDp = departments[department.val()];
var thisData = filterValuesInArray(data, 'university', currentUn);
thisData = filterValuesInArray(thisData, 'department', currentDp);
supervisors = getValuesInObjs(thisData, 'supervisor');
setSelectOptions(supervisor, supervisors);
supervisor.trigger('change');
})
supervisor.change(function () {
currentSp = supervisors[supervisor.val()];
})
confirmBtn.click(function () {
var thisData = filterValuesInArray(data, 'university', currentUn);
thisData = filterValuesInArray(thisData, 'department', currentDp);
thisData = filterValuesInArray(thisData, 'supervisor', currentSp);
contentDiv.empty();
thisData.forEach(function (value, i) {
var desc = value['description'];
var rate = value['rate']
var card = $(`<div class="card mb-3">
<h5 class="card-header" >${currentUn}${currentDp}</h5 >
<div class="card-body">
<h3 class="card-title">${currentSp}</h3>
<p class="card-text">评分:${rate}</p>
<p class="card-text">${desc}</p>
</div></div >`);
contentDiv.append($(card));
})
});
setSelectOptions(schoolcate, schoolcates);
schoolcate.trigger('change');
</script>
</body>
</html>