Yii T ButtonGroup无效

Yii T ButtonGroup无效

问题描述:

    <?php $this->widget('bootstrap.widgets.TbButtonGroup', array(
    'type'=>'success', 
    'buttons'=>array(
        array('label'=>'Action', 'url'=>'#'),
        array('items'=>array(
            array(
                'label'=>'set approved',
                'url'=>$this->createUrl('controller/dostuff'),
                'buttonType'=>'ajaxButton',
                'ajaxOptions'=>array(
                      'beforeSend' => 'function( request ) {
                          alert(request);
                        }'
                      ,
                      'success' => 'function( data ) {
                          alert(data);
                        }'
                      ,
                  ),
            ),
            array('label'=>'set blocked', 'url'=>'#', 'buttonType' => 'ajaxLink'),
            array('label'=>'set pending', 'url'=>'#', 'buttonType' => 'ajaxLink'),

        )),
    ),
)); ?>

I tried a lot but I cannot get this working.. I want to use yiis ajax behaviour on the first button of the buttongroup.. I dont even get javascript errors or anything.. just if I click the link it redirects me to the url - no ajax at all. Maybe you have an idea

I see in the TbButton file, see run() method:

public function run()
{
    echo $this->createButton();

    if ($this->hasDropdown())
    {
        $this->controller->widget('bootstrap.widgets.TbDropdown', array(
            'encodeLabel'=>$this->encodeLabel,
            'items'=>$this->items,
            'htmlOptions'=>$this->dropdownOptions,
        ));
    }
}

If the button contained in items, it will instance of TbDropdown, not TbButton; So buttonType and ajaxOption you tried to provide are useless.

You can choose another solution to replace this solution. You can set id for each item and write javascript to do ajax manualy.