在编辑时使用 select2 在输入中显示选定的多个选定项目 [英] show the selected multiple selected items in input using select2 on edit

查看:45
本文介绍了在编辑时使用 select2 在输入中显示选定的多个选定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在编辑时获取多选输入字段中的选定值.

I want to get the selected values in the multiple select input field on edit.

我正在使用 select2 version:4

  • 我有一个 产品 表单,其中有一个名为条件"的字段,该字段使用 select2 多选选项.
  • 目前工作正常.我也将这些数据添加到数据库中.
  • 但是当我想编辑同一个产品时,我想显示数据库中先前选择的条件项目.
  • I am having a product form which is having a field called "condition" which is using select2 multi select option.
  • its working fine for now. i am adding these data to database as well.
  • but when i want to edit the same product i waant to show the previously selected conditions items which are in database.

我如何在 select2 中实现这一点.

How can i achieve this in select2.

请将帮助我完成此操作的链接发送给我.

Please send me the link which helps me to do this.

推荐答案

试试这个 (Select2 V.4)

Try this one (Select2 V.4)

 <select id="example" multiple="multiple" style="width: 300px">
    <option value="JAN">January</option>
    <option value="FEB">February</option>
    <option value="MAR">March</option>
    <option value="APR">April</option>
    <option value="MAY">May</option>
    <option value="JUN">June</option>
    <option value="JUL">July</option>
    <option value="AUG">August</option>
    <option value="SEP">September</option>
    <option value="OCT">October</option>
    <option value="NOV">November</option>
    <option value="DEC">December</option>
</select>

<script>
  $('#example').select2({
      placeholder: 'Select a month'
  });

  $(function(){
    $("#example").select2().val(["FEB","JUN"]).trigger('change.select2');
  });
</script>

这篇关于在编辑时使用 select2 在输入中显示选定的多个选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆