廢話不多說;我說的老版本就是要求初始元素為input;
<input id='example' value='2'/>
下面是data格式
data: [ { "id": "1", "text": "張三" }, { "id": "2", "text": "李師師" }, { "id": "3", "text": "林沖" }, { "id": "4", "text": "周通" },{ "id": "5", "text": "楊康" } ],
$('#example').select2({
placeholder:'默認值',//上面給了value;這里就不起作用了
ajax:{
//省略
results:function () {}
},
initSelection: function (element, callback) {
var initId = $(this).val();
var initData = {id: initId, text:'默認值'}
callback(initData)
}
})
應該就是這樣了。大概就是這樣,來不及測了;