여기 내 코드를 가져 와서 db 옵션을 사용하여 데이터베이스를 만듭니다. 알파벳순으로 표시하고 싶습니다. 나는 sort() 함수를 시도했지만 도움이되지는 않았다.json 개체를 특정 val에 정렬 하시겠습니까?
$(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);
});
}
나는 val.sort()를 시도했다; json, sort(); – dua
json 코드는 입니다. public function get_makes_ajax() { $ json = $ this-> ajax_get_makes(); $ this-> response-> addHeader ('Content-Type : application/json'); $ this-> response-> setOutput (json_encode ($ json)); } – dua
샘플 JSON을 제공해 주시겠습니까? 정렬 방법에 대한 일부 규칙/가이드 –