0

我创建了 Yii Bootstrap TbMenu。如何动态添加活动类?

$this->widget('bootstrap.widgets.TbMenu',
    array(
        'type' => 'list',
        'items' => array(
            array(
                'label' => 'Home',
                'url' => '#',
                'itemOptions' => array('class' => 'active')
            ),
            array('label' => 'Library', 'url' => '#'),
            array('label' => 'Applications', 'url' => '#'),
        )
    )
);
4

1 回答 1

0

也许与 inline if?

$this->widget('bootstrap.widgets.TbMenu',
array(
    'type' => 'list',
    'items' => array(
        array(
            'label' => 'Home',
            'url' => '#',
            'itemOptions' => (($isActive) ? array('class' => 'active') : array())
        ),
        array('label' => 'Library', 'url' => '#'),
        array('label' => 'Applications', 'url' => '#'),
    )
)

);

于 2013-09-21T09:40:47.777 回答