0
我一直與MagicSuggestion幾天的:Magicsuggest改變選擇編程
<div>
<div id="magicsuggest"></div>
</div>
VehicleNameList = [{id: 1, name: "Volvo"},
{id: 2, name: "Audi"},
{id: 3, name: "Volkswagen"}]
vehicleNameSelected = "Volvo"
magicVehicleChange = $('#magicsuggest').magicSuggest({
data: VehicleNameList,
placeholder: function() {
$('.ms-sel-ctn input').attr("placeholder", vehicleNameSelected);
}
});
$(magicVehicleChange).on('selectionchange', function (e, m, sel) {
if (sel.length == 0) return;
for (i = 0; i < VehicleNameList.length; i++) {
if (typeof sel[0] != 'undefined')
if (VehicleNameList[i].name == sel[0].name) {
vehicleNameSelected(sel[0].name);
break;
}
}
if (typeof sel[0] != 'undefined') {
magicVehicleChange.collapse();
this.clear();
}
});
的問題是,我想更改選定車輛名稱當按鈕被改變,例如以「大衆汽車「,通過呼籲:
magicVehicleChange.setValue([{ name: "Volkswagen", value: 3 }])
但沒有成功。我做錯了什麼?有沒有辦法在按下按鈕時更改選擇?