Select2 and initSelection callback

后端 未结 2 1386
日久生厌
日久生厌 2020-12-28 14:03

On page load, I\'m trying to use initSelection to select ID 60 (specified value of the input field). I can\'t seem to get it to work properly.

The PHP scrip

2条回答
  •  遥遥无期
    2020-12-28 14:56

    Finally solved it! I figured select2 didn't want an array since it's a single value, so I selected the first element of the data.results array.

    callback(data.results[0]);
    

    And if you have set multiple:true, just accept the entire results array;

    callback(data.results);
    

提交回复
热议问题