Hier ist mein Code Abruf von db nach Jahr in Option jetzt möchte ich alphabetisch anzeigen lassen. Ich habe versucht, sort() -Funktion, aber nichts passiert, bitte helfen.Sortier-JSON-Objekt für bestimmtes Wert?
$(document).ready(function() {
//on change year change makes
$('#years').change(function() {
$('#makes').attr("disabled",true);
$('#makes').empty();
$('#makes').append($("<option></option>")
.attr("value", 0)
.text("Select Makes"));
$.get('index.php?route=common/custom_search/get_makes_ajax&token=<?php echo $token; ?>',
function (json) {
if (json) {
$.each(json, function (key, val) {
$('#makes')
.append($("<option></option>")
.attr("value", key)
.text(val));
console.log(json);
});
$('#makes').removeAttr("disabled");
// console.log(json);
} else {
console.log('this is not working!');
}
});
$('#models').attr("disabled",true);
$('#sub_models').attr("disabled",true);
$('#engines').attr("disabled",true);
$('#parts').attr("disabled",true);
$('#search_button').attr("disabled",true);
});
}
Ich habe versucht val.sort(); json, sort(); – dua
JSON-Code ist öffentliche Funktion get_makes_ajax() { $ json = $ this-> ajax_get_makes(); $ this-> response-> addHeader ('Content-Type: application/json'); $ this-> response-> setOutput (json_encode ($ json)); } – dua
} Könnten Sie bitte ein Beispiel JSON zur Verfügung stellen, und einige Regeln/Anleitung, wie Sie es sortiert haben möchten –