【问题标题】:cakephp3 and select2 how to reset the first valuecakephp3 和 select2 如何重置第一个值
【发布时间】:2026-01-30 11:05:02
【问题描述】:

我正在使用 cakephp3 和 select2 下拉脚本。

我对数据的调用如下所示

$roles = $this->ParticipantsProjectsRoles->Roles->find('list', [
         'keyField' => 'id',
         'valueField' => 'description'
]);

在我看来我称之为

<?=$this->Form->input('role_id', ['options' => $roles, 'label' => false, 'class' => 'form-control select2me']);?>

输出 HTML 将始终将第一个数据条目加载到选择中。 有没有办法让第一个值始终为空?

【问题讨论】:

    标签: cakephp select2


    【解决方案1】:

    options 数组中的empty 键设置为true 或其他值,例如Select Role:

    $this->Form->input(
        'role_id', [
            'options' => $roles,
            'label' => false,
            'class' => 'form-control select2me',
            'empty' => true
        ]
    );
    

    【讨论】:

    • 天啊!很简单!太感谢了!!我真是瞎了眼!
    最近更新 更多