我有一个 Select2 输入,它是一个文本框,我这样做了
<input type="text" class="selectbox" name="selectbox['.$row[0].']" />
我应该像这样从mysql动态设置初始值,value="'.$row[1].'"
但它不起作用。
这是我设置select2的Jquery:
$(".selectbox").select2({
placeholder: "Search for a Golf Course",
minimumInputLength: 1,
ajax: {
url: "functions/searchGolfCourses.php",
quietMillis:100,
dataType: 'json',
params: {
method: 'post'
},
data: function (term, page) {
// Data to be sent to the server. Usually it is just the "term"
// parameter (and page if using pagination).
// However, since this API simply echoes back what we send,
return { s: term /* 's' is passed to php as $_POST['s'], this will contains the user input*/
}
},
results: function(data, page) {
//data param === received response from the server. As dataType
//is json, jQuery automatically parses the response into an object.
return { results: data };
}
}
});
知道如何设置 Select2 输入框的初始值吗?提前致谢