YII :

2012-02-26 2 views
0

이 나와 함께 많은 시간을 일이, 나는 그들의 대부분을 해결하기 위해 관리하지만, 여기에 또 다른 새로운 문제 :YII :

Checkboxlist를 사용하면 Ajax 작업 후 select all이라는 체크 박스가 있는데,이 상자를 클릭하면 다른 모든 체크 박스가 선택되지 않게됩니다. 그럼 어떻게 새로 고쳐야합니까?

<?php 
     $filterList = array(
      'first' => 'first option', 
      'second' => 'second option', 
      'third' => 'third option', 

     ); 
     $htmlOptions = array(
      'checkAll'=>'Select All', 
      'separator' => ' ', 
      'template' => '{input}&nbsp;{label}<br/>' 
//   'template' => '<tr><td >{label}</td><td>{input}</td></tr>' 
     ); 
     echo CHtml::checkBoxList('filters', array('1'), $filterList, $htmlOptions) 
     ?> 

다음은 jQuery를

jQuery('#filters_all').click(function() { 
    jQuery("input[name='filters\[\]']").attr('checked', this.checked); 
}); 
jQuery("input[name='filters\[\]']").click(function() { 
    jQuery('#filters_all').attr('checked', !jQuery("input[name='filters\[\]']:not(:checked)").length); 
}); 
jQuery('#filters_all').attr('checked', !jQuery("input[name='filters\[\]']:not(:checked)").length); 

답변

1

난 당신이 .click() 기능을 사용하여 클릭 이벤트 처리기를 바인딩한다고 가정하는 것,하고있어 생성됩니다 다음 당신의 AJAX 호출의 결과로, 당신은 요소를 대체하고 있습니다.

하나는 AJAX 호출의 일부로 요소를 교체하거나하지 않을 요소에 이벤트 핸들러를 할당 (jQuery를하기 전에 1.7) 기능을 .on() (jQuery를 1.7+) 또는 .delegate()를 사용하지 않는 교체과 같이 수 :

$('body').on('click', 'selector', function(e) { 
    // select all checkboxes here 
}); 

또는

$('body').delegate('selector', 'click', function(e) { 
    // select all checkboxes here 
}); 
+0

내가 통해 UR 관심을 가져 주셔서 감사합니다 당신의 가정을 이해하지 못했다 원인, 생성 된 jQuery 코드를 추가하면 더 기반으로 정교한 수 있기를 희망했습니다 그 편집 –