how to retain Select2 results after select?

喜欢而已 提交于 2020-01-05 04:32:10

问题


For example, when using select2 muti-value, user entered 'new', and it showed

  • New Mexcio
  • New Hampshire
  • New Jersey
  • New York

After selecting 'New Mexcio', and the user would like to select again from the rest of the 3 remaining. In order to to do that, the user has to enter 'new' again.

Is there a way to retain the results instead of clear out the 'query?

Thanks


回答1:


Sounds like you want to persist a query from one search to the next. You might want to check out the nextSearchTerm property.

To display the current value in the next search,

function displayCurrentValue(selectedObject, currentSearchTerm) {
  return currentSearchTerm;
}

$("#e1").select2({
  nextSearchTerm: displayCurrentValue
});


来源:https://stackoverflow.com/questions/23985492/how-to-retain-select2-results-after-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!