我有一個filter_horizontal選擇器在我的Django管理員有一個產品的類別列表(這是在管理產品頁面)。我想根據在filter_horizontal框中選擇的類別或類別更改產品更改窗體的外觀。使用jQuery來確定何時Django的filter_horizontal更改,然後獲取新的數據
我想每次將類別從filter_horizontal的from或section移動到某個段時調用一個函數。
我現在擁有的是:
(function($){
$(document).ready(function(){
function toggleAttributeSection(choices) {
$.getJSON('/ajax/category-type/', { id: choices}, function (data, jqXHR) {
// check the data and make changes according to the choices
});
}
// The id in the assignment below is correct, but maybe I need to add option[]??
var $category = $('#id_category_to');
$category.change(function(){
toggleAttributeSection($(this).val());
});
});
})(django.jQuery);
功能當我移動的類別從左側到右側不會被調用,或反之,則filter_horizontal的。
我假設$ category.change()是不正確的,但我不知道filter_horizontal更改時可能觸發哪些其他事件。另外,我知道在選擇框內有多個選項。我還沒有那麼遠,但我如何確保所有這些都傳遞給函數?
如果任何人都可以指出我正確的方向,我將非常感激。謝謝!