[英]Select2 Posting Ids instead of text
我正在用遠程數據(json)初始化select2(multiple),並且在提交表單時,select2提交所選文本的索引,它可以返回所選文本(以逗號分隔,類似於索引)而不是索引嗎?
<input type="hidden" id="IntendedCourses" name="IntendedCourses"/>
$.getJSON("GetCourses.aspx", function (course) {
$("#IntendedCourses").select2({
multiple: true,
data: course
});
});
json格式:
[{"id":"0","text":"Accounting"},{"id":"1","text":"Accounting & Finance"},{"id":"2","text":"Aeronautical"},{"id":"3","text":"Aerospace Engineering"}]
我相信您需要的是:
$("#IntendedCourses").change(function() {
var selection = (JSON.Stringify($("#IntendedCourses").select2('data')));
});
這應該為您提供更改后所選內容的JSON。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.