如何禁用 yii2 ActiveFrom dropDownList 中的一项?

Xiu*_*ong 4 yii2

Yii2 主动形式

<?= $form->field($model, 'pid')->dropDownList([1=>1,2=>2])->hint('????') ?>
Run Code Online (Sandbox Code Playgroud)

我想禁用选项 2=>2。

有没有办法做到这一点?

jag*_*ler 5

您可以使用“选项”键为下拉列表中的所有项目添加属性。假设您要禁用第二项。

<?= $form->field($model, 'pid')->dropDownList([1 => 1, 2 => 2], ['options' => [2 => ['disabled' => true]]])->hint('????') ?>
Run Code Online (Sandbox Code Playgroud)

在文档中:http ://www.yiiframework.com/doc-2.0/yii-helpers-basehtml.html#activeDropDownList() -detail