好吧,在研究了如何使用 Yii 绑定activate( event, ui )
或beforeActivate( event, ui )
事件之后……我没有成功。
但是,我找到了一种使用 htmlOptions 拉出回调的解决方法,这是我的 CJuiAccordion 渲染代码:
$panels = array(
"Panel a" =>
"content goes here",
"Panel B" =>
"content goes here",
"Panel C" =>
"content goes here"
);
$cs = Yii::app()->clientScript;
//my required jquery function is declared in this file
$cs->registerScriptFile('js/accordion.js');
$this->widget('zii.widgets.jui.CJuiAccordion', array(
'panels'=>$panels,
'id'=>'inventory-accordion',
'options'=>array(
'collapsible'=>true,
'active'=>-1,
'heightStyle'=>'content',
),
'htmlOptions'=>array(
'style'=>'width:100%;',
'onclick'=>'togglePanels("inventory-accordion","h3")',
),
)
);
这是很好的代码,js/accordion.js
/**
* Makes a jquery-ui-accordion hide all of its unactive panels whenver one is
* selected and shows all the panels when the only active panel is collapsed
*/
function togglePanels(accordionId, headerSelector){
var accordion = $("#"+accordionId);
var accordionHeader = $("#"+accordionId+"> "+headerSelector);
var active = accordion.accordion("option","active");
if (active!==false) {
//alert(active);
accordionHeader.each(
function(index){
if (index!=active) $(this).slideUp('slow');
}
);
} else{
//alert("Show all the panels!");
accordionHeader.each(
function(){
$(this).slideDown('slow');
}
);
}
}
我很确定这段代码很有帮助,并且可以为 CJuiAccordion 的 Yii 用户进行调整。