1
다른 선택 상자 (AJAX 사용)의 값에 따라 선택 상자의 내용을 변경하는 일부 jQuery가 있습니다. PHP는 배열 (TypeDescriptionData.name으로 정렬)을 원하는대로 반환하지만 목록은 JS의 어딘가에서 다시 정렬됩니다. 어떤 아이디어?JSON이 반환 목록을 재정렬합니다
는PHP 전화 : 여기
public function get_descriptions_by_type($typeId) {
$this->autoRender = false;
$this->loadModel('TypeDescriptionData');
$data = array();
$this->TypeDescriptionData->contain();
$descriptions = $this->TypeDescriptionData->find('list', array('conditions' => array('type_data_id' => $typeId), 'order' => 'name ASC'));
if(isset($descriptions) && is_array($descriptions)) {
foreach($descriptions as $x => $y) {
$data[$x] = $y;
}
}
echo json_encode($data);
}
위로 json_encode PHP를 호출 한 후 JSON 오른쪽 것 : 여기
{
"1":"FD 50",
"9":"Hypercom T4210",
"2":"Hypercom T7P",
"8":"Hypercom T7Plus",
"10":"Nurit 2085",
"11":"Nurit 8400",
"12":"Nurit 8400 Lite",
"17":"Other Terminal",
"13":"Verifone Tranz 330",
"14":"Verifone Tranz 380",
"15":"Verifone Vx510",
"16":"Verifone Vx510 LE"
}
은 JS의 :
$('#TypeType').change(function() {
$('#TypeDescription').find('option').remove().end();
$.ajax({
url:'/TypeData/get_descriptions_by_type/' + $(this).val(),
type:'POST',
dataType: 'json',
success: function(json) {
console.log(JSON.stringify(json));
$.each(json, function(i, value) {
$('#TypeDescription').prepend($('<option>').text(value).attr('value', i));
});
}
});
});
그리고 여기에 내가 추가 할 경우 JSON을의 "console.log (JSON.stringify (json));" 상기 JS에서 "기능 (JSON) {성공"바로 뒤에
{
"1":"FD 50",
"2":"Hypercom T7P",
"8":"Hypercom T7Plus",
"9":"Hypercom T4210",
"10":"Nurit 2085",
"11":"Nurit 8400",
"12":"Nurit 8400 Lite",
"13":"Verifone Tranz 330",
"14":"Verifone Tranz 380",
"15":"Verifone Vx510",
"16":"Verifone Vx510 LE",
"17":"Other Terminal"
}
원시 JSON 모양은 무엇입니까? I.E. 응답의 내용 –