JavaScript と Elementmanipulation を使用してこれを行うことができます。
車のモデルを JavaScript Vars に保存します。
<script type="text/javascript">
var porsche = {{ porsche|safe }};
var vw = {{ vw|safe }};
</script>
JavaScript では、親の選択ボックスに新しい Change Method を指定できます。
$('#parent_select').change(function(){
changeCars();
});
関数は、子選択ボックスを操作できます。
var newCarList = [];
val =$('#parent_select').val();
if (val=='porsche'){
newCarList = porsche;
}
else if (val == 'vw'){
newCarList = vw;
}
else{
//some Error handling
}
select = document.getElementById('child_select');
while (select.firstChild) {
select.removeChild(select.firstChild);
// to remove all previously added childs (option fields)
}
for (var i = 0; i < newCarList.length; i ++){
var opt = document.createElement('option');
opt.value = newCarList[i];
opt.innerHTML = newCarList[i];
select.appendChild(opt);
//append all new Childs to the child_select
}
この可能性は機能しますが、オブジェクト操作は最速の方法ではないため、非常に遅くなります。もう 1 つの可能性は、別の子選択を作成し、表示/非表示を使用して、parent_select の値に従って正しい子選択のみを表示することです。