-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeoFilter.js
66 lines (49 loc) · 1.52 KB
/
geoFilter.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
// Inicializador
$(function () {
$('.selectpicker').selectpicker();
});
getAllData();
var datos;
var localidades;
function getAllData() {
$.ajax({
url: 'datos.json',
async: false,
dataType: 'json',
success: function (json) {
datos = json.localidades;
}
});
}
function getFilteredByKey(array, key, value, value2, value3) {
return array.filter(function (e) {
return e[key] == value && e["provincia"].nombre == value2 && e["localidad_censal"].nombre == value3;
});
}
function getLocalidades(array, value) {
return array.filter(function (e) {
var array_filtrado = {};
array_filtrado = e["provincia"].nombre == value;
return array_filtrado;
});
}
async function cambiarLocalidades() {
var itemSelectorOption = $('#select-localidad option');
itemSelectorOption.remove();
var provincia = document.getElementById('select-provincia').value;
array = await getLocalidades(datos, provincia);
select = document.getElementById('select-localidad');
array = array.sort();
array.forEach(element => {
optionText = element.nombre;
optionValue = element.nombre;
$('#select-localidad').append(`<option value="${optionValue}">
${optionText}
</option>`);
});
$('#select-localidad').selectpicker('refresh');
}
function removeOptions() {
document.getElementById('select-localidad').innerHTML = "";
}
cambiarLocalidades();