我希望能在使用jquery easy autocomplete方面得到一些帮助。它工作正常,但我无法启用按键事件(我希望按Enter键时我们将重定向到正确的链接)。我想使用onChooseEvent,但我不确定如何正确使用它。
我的代码:
<script>
// http://easyautocomplete.com/guide#sec-template-links
$(function() {
var options = {
data: [
{"text": "Amazon", "website-link": "https://www.babelway.com/technology/amazon-mws/"},
{"text": "AS2", "website-link": "https://www.babelway.com/technology/as2/"},
{"text": "CSV", "website-link": "https://www.babelway.com/product-tour/csv-erp/"},
{"text": "Dropbox", "website-link": "https://www.babelway.com/technology/b2b-integration-dropbox/"},
{"text": "Edifact", "website-link": "https://www.babelway.com/technology/edifact/"},
{"text": "Email", "website-link": "https://www.babelway.com/technology/b2b-integration-email/"},
{"text": "Excel", "website-link": "https://www.babelway.com/technology/excel-erp/"},
{"text": "Flat File", "website-link": "https://www.babelway.com/technology/flat-file/"},
{"text": "FTP", "website-link": "https://www.babelway.com/technology/b2b-integration-ftp/"},
{"text": "HTTP", "website-link": "https://www.babelway.com/technology/b2b-integration-http/"},
{"text": "Idoc", "website-link": "https://www.babelway.com/technology/sap-idoc/"},
{"text": "Json", "website-link": "https://www.babelway.com/technology/b2b-integration-json/"},
{"text": "OFTP", "website-link": "https://www.babelway.com/technology/oftp/"},
{"text": "Peppol", "website-link": "https://www.babelway.com/technology/peppol/"},
{"text": "Rosettanet", "website-link": "https://www.babelway.com/technology/rosettanet/"},
{"text": "SAP", "website-link": "https://www.babelway.com/technology/sap-edi/"},
{"text": "SFTP", "website-link": "https://www.babelway.com/technology/b2b-integration-sftp/"},
{"text": "Tradacoms", "website-link": "https://www.babelway.com/technology/Tradacoms/"},
{"text": "UBL", "website-link": "https://www.babelway.com/technology/ubl/"},
{"text": "VAN", "website-link": "https://www.babelway.com/technology/van/"},
{"text": "X12", "website-link": "https://www.babelway.com/technology/x12/"},
{"text": "X400", "website-link": "https://www.babelway.com/technology/x400/"},
{"text": "XML", "website-link": "https://www.babelway.com/technology/xml-edi/"}
],
getValue: "text",
template: {
type: "links",
fields: {
link: "website-link"
}
},
list: {
showAnimation: {
type: "fade", //normal|slide|fade
time: 400,
callback: function() {}
},
hideAnimation: {
type: "slide", //normal|slide|fade
time: 400,
callback: function() {}
},
match: {
enabled: true
},
onChooseEvent: function() {
}
}
};
$("#template-links").easyAutocomplete(options);
});
</script>
感谢您的帮助:)
答案 0 :(得分:0)
答案 1 :(得分:0)
Sorry for the late reply. Please add these two lines inside your `onCHoseEvent` method. Eg:
onChooseEvent: function() {
let selected = $("#template-links").getSelectedItemData();
location.replace(selected["website-link"]);
}
在选择并按Enter键后,getSelectedItemData()
方法将返回所选text
的数据对象,有点像{text: "Amazon", website-link: "https://www.babelway.com/technology/amazon-mws/"}
的{{1}}。并且Amazon
将返回selected["website-link"]
的值(上述情况为website-link
)。
通过在链接上调用https://www.babelway.com/technology/amazon-mws/
方法,您将能够重定向。
希望,这会有所帮助。谢谢。