당신은 자바 스크립트와 Elementmanipulation하여이 작업을 수행 할 수 있습니다 : 예
<script type="text/javascript">
var porsche = {{ porsche|safe }};
var vw = {{ vw|safe }};
</script>
을 그리고 당신은 당신의 부모 선택에 대한 새로운 변경 방법을 지정할 수 있습니다 자바 스크립트 :
는 자바 스크립트를 바르에 자동차 모델을 저장 상자 :
$('#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
}
이 가능성은 작동하지만 객체 조작이 가장 빠른 방법이 아니기 때문에 매우 느립니다. 또 다른 가능성은 parent_select의 값에 따라 다른 하위 선택을 작성하고 show/hide를 사용하여 올바른 선택 만 표시하는 것입니다.
출처
2014-07-11 10:28:32
gaw
나는 당신의 질문을 명확히하고 예제를 개선하려고 노력했다. 올바른지 확인하십시오. 나는 이것에 또한 흥미있다. – Deepend
예, 그게 내가 말하려고했던 것입니다. 고맙습니다. 희망은 지금 대답을 얻을 것입니다 .. – mihai
내 문제를 해결했습니다. 나는 장고 smart_selects를 사용했다. https://github.com/digi604/django-smart-selects – mihai