【问题标题】:set value on select2 multiple from php with laravel 5.2使用 laravel 5.2 在 php 中设置 select2 多个值
【发布时间】:2017-05-05 11:02:06
【问题描述】:

在我的控制器中

$this->selectedUsers = UserTipepermintaanRelationship::where('permintaan_tipe_id', $id)->pluck('user_id', 'user_id');

上面的对象会给出输出:

1 => 1
2 => 2
25 => 25

在我的 html 中:

{!! Form::select('user_id[]', $users, isset($tipePermintaan) ? $selectedUsers : null, ['class' => 'form-control select-user', 'multiple']) !!}

我想用selectedUsers 设置我的select2 多个值。

但我无法在我的 select2 倍数上设置值。我哪里做错了?

【问题讨论】:

  • 你使用的是 Laravel 4.* 还是 Laravel Collective?
  • 能否提供完整代码?

标签: laravel jquery-select2


【解决方案1】:

我认为您需要更新您的代码,例如:

{!! Form::select('user_id[]', $users, (isset($tipePermintaan) ? $selectedUsers : null), ['class' => 'form-control select-user', 'multiple']) !!}

【讨论】:

    【解决方案2】:

    $this->selectedUsers 是集合,但对于Form::select,第三个参数必须是带键的数组。所以你需要:

    $this->selectedUsers = UserTipepermintaanRelationship::where('permintaan_tipe_id', $id)->pluck('user_id')->toArray();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-14
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-04
      • 2018-11-03
      相关资源
      最近更新 更多