我想使用条件语句创建多个URL,以检查它是A类还是B类,当我单击A类上的项目时,它应该是something.com/A,反之亦然,我试图创建一个if条件来在清单对象内的onClickEvent函数中检查someOption.categories.listLocation ='A',然后用A运行window.location.href,反之亦然,似乎没有用。
var someOption = {
url: function (phrase) {
return window.location.origin + '/json/something/';
},
categories: [{
listLocation: "A",
maxNumberOfElements: 5,
header: "A"
}, {
listLocation: "B",
maxNumberOfElements: 5,
header: "B"
}],
getValue: function (element) {
return element.character;
},
ajaxSettings: {
dataType: "json",
method: "GET",
data: {
dataType: "json"
}
},
preparePostData: function (data) {
data.q = $("#ajax-something").val();
return data;
},
requestDelay: 100,
list: {
onClickEvent: function (event) {
let values = $('#ajax-something').val();
window.location.href = window.location.origin + '/A/' + $('#ajax-something').getSelectedItemData().character
},
maxNumberOfElements: 10,
match: {
enabled: false
},
sort: {
enabled: true
}
},
theme: "square"};
$("#apartment-ajax-rent").easyAutocomplete(someOption);