1
我试图实现marcopolo,这是一个jQuery插件来做自动完成。如何实现自动完成使用jquery marcopolo
这是我的两个问题。
1)如果我输入单个字母或任何单词,将出现“方向”的所有值,这是不正确的。例如,如果我搜索“向上”,则会出现带有这两个字母的任何单词。
2)如果用户搜索“Up”并且他们按回车或点击提交按钮,他们应该被带到与该单词关联的URL。
Github的参考:https://github.com/jstayton/jquery-marcopolo
马可波罗例如:http://jstayton.github.io/jquery-marcopolo/example1.html
这是我的codepen:http://codepen.io/anon/pen/rrwgwJ
HTML
<input type="text" name="autoCom" id="autoCom"><input type="submit" class="send">
CSS
ol {position: absolute; top: 20px;}
ol.mp_list {list-style-type: none;}
JS
$(function(){
$('#autoCom').marcoPolo({
url: 'https://api.myjson.com/bins/ygdk',
minChars: 1,
submitOnEnter: true,
formatData: function (data) {
return data; //possible issue
},
formatItem: function (data, $item) {
return data.Direction;
},
onSelect: function (data, $item) {
//window.location = data.URL;
this.val(data.Direction);
window.open(data.URL,'_blank');
}
});
});
感谢您的帮助!
对不起,这个JSON的新东西。我正在查看https://gist.github.com/jstayton/1008099上的代码。就像代码的第35行一样,我是否需要在JS中添加“param:'query'”?或者有什么我需要在JSON文件中更新?谢谢! – user2428993
Marcopolo将您在文本框中键入的内容发送到服务器,假设服务器将过滤您的输出,但它永远不会被过滤,然后服务器始终返回相同的结果。 –