0

我正在尝试输出 CHtml::radioButtonList (yii 1.1.14),每个渲染元素看起来如下所示:

<input id="option_0" type="radio" name="MyForm[customOption_id]" value="1" data-ref="a string contained in table, column ref">
<label for="option_0">Some option</label>

让我头疼的是 data-ref 属性。

代码

<li>
<?php 
echo $form->radioButtonList(
        $model,'refinement_id',
        CHtml::listData($refinements, 'id', 'label'),
        array('separator'=>'</li><li>', 'container' => '')); 
?>
</li>

我想为每个输出一个 data-ref 属性,然后我可以在某些 JavaScript 中使用它。

据我所知,我无法将其添加到 radioButtonList 的 htmlOptions 数组中,因为我只能在此处提供静态值。

非常感谢这里的任何指针或有人告诉我我在吠叫错误的树。

4

1 回答 1

1

data-ref 的内容取决于值还是静态?如果它不是静态的,使用 $form->radioButtonList 是不可能的,请使用老式方法执行此操作。否则很简单

<?php 
echo $form->radioButtonList(
    $model,'refinement_id',
    CHtml::listData($refinements, 'id', 'label'),
    array('separator'=>'</li><li>', 'container' => '', 'data-ref'=>'fshafh')); 
?>
于 2014-04-16T18:53:39.820 回答