我试图运行http://easyautocomplete.com/example/select-event
但每当我填写inputOne时,它返回错误:
Uncaught TypeError: $(...).getSelectedItemIndex is not a function
at Object.onSelectItemEvent (data.js:6)
at HTMLDivElement.<anonymous> (jquery.easy-autocomplete.min.js:10)
getSelectedItemData() at HTMLDivElement.dispatch (jquery-1.11.2.min.js:3)
at HTMLDivElement.r.handle (jquery-1.11.2.min.js:3)
at Object.trigger (jquery-1.11.2.min.js:3)
at HTMLDivElement.<anonymous> (jquery-1.11.2.min.js:3)
at Function.each (jquery-1.11.2.min.js:2)
at m.fn.init.each (jquery-1.11.2.min.js:2)
at m.fn.init.trigger (jquery-1.11.2.min.js:3)
at j (jquery.easy-autocomplete.min.js:10)
代码(html):
<script src="http://easyautocomplete.com/javascripts/jquery-1.11.2.min.js"></script>
<script src="http://easyautocomplete.com/dist/jquery.easy-autocomplete.min.js"></script>
<link rel="stylesheet" href="http://easyautocomplete.com/dist/easy-autocomplete.min.css">
<input id="inputOne" placeholder="X-men character" />
<input id="inputTwo" placeholder="Real name" />
<script>
var options = {
data: [
{"character": "Cyclops", "realName": "Scott Summers"},
{"character": "Professor X", "realName": "Charles Francis Xavier"},
{"character": "Mystique", "realName": "Raven Darkholme"},
{"character": "Magneto", "realName": "Max Eisenhardt"},
{"character": "Storm", "realName": "Ororo Monroe"},
{"character": "Wolverine", "realName": "James Howlett"}
],
getValue: function(element) {
return element.character;
},
list: {
onSelectItemEvent: function() {
var selectedItemValue = $("#inputOne").getSelectedItemData().realName;
$("#inputTwo").val(selectedItemValue).trigger("change");
},
onHideListEvent: function() {
$("#inputTwo").val("").trigger("change");
}
}
};
$("#inputOne").easyAutocomplete(options);
</script>
我正在运行python flask来提供文件。让我知道你的想法。