How to get Selected Text from select2 when using <input>

前端 未结 9 1237
心在旅途
心在旅途 2020-12-12 23:38

I am using the select2 control, loading data via ajax. This requires the use of the tag.

Now, I want to retrieve the selecte

9条回答
  •  再見小時候
    2020-12-13 00:03

    In Select2 version 4 each option has the same properties of the objects in the list;

    if you have the object

    Obj = {
      name: "Alberas",
      description: "developer",
      birthDate: "01/01/1990"
    }
    

    then you retrieve the selected data

    var data = $('#id-selected-input').select2('data');
    console.log(data[0].name);
    console.log(data[0].description);
    console.log(data[0].birthDate);
     
    

提交回复
热议问题