在网上找了各种办法后的效果为多次选中取消时会发生选中出现失败的问题,经过测试后,发下如下代码有效。
<script>
var heatmap_all = {{ heatmap|safe }};
$('input:radio[name="department"]').click(function(){
var $radio = $(this);
if ($radio.data('waschecked') == true){
$radio.prop('checked', false);
$("input:radio[name='department']").data('waschecked',false);
// $radio.data('waschecked', false);
showHeatmap(heatmap_all);
} else {
$radio.prop('checked', true);
$("input:radio[name='department']").data('waschecked',false);
$radio.data('waschecked', true);
$.ajax({
url: "/networkData/",
type: "POST",
data: {'csrfmiddlewaretoken':'{{ csrf_token }}','department': $radio.context.value},
traditional: true,
success: function (data){
heapmap = data['heatmap'];
showHeatmap(heapmap);
}
});
}
});
</script>
<input type="radio" name="department" value={{i}}>