jQuery的自动完成 - 与code帮助 - 何去何从? [英] Jquery Autocomplete - help with code - what next?
问题描述
我在这里使用这个插件:
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/一>
I'm using this plugin here: http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
我有这样的:
function formatar(result) {
return result.q + ' (teste ko)';
}
$(document).ready(function() {
$('#nome_dominio').autocomplete("testeJson2.php", {
parse: function(data) {
alert(data);
//what now?
},
formatItem: function(result) {
return formatar(result);
}
}).result(function(e, result) {
alert ('you have choose something');
});
});
如果我们提醒(数据),我们得到的结果完全一样如此:
If we alert(data), we DO get the results exactly like so:
[{"nomeDominio":"aaaa.hk"},{"nomeDominio":"agentesdeexecucao.hk"}]
我认为下一步应该在某种程度上插件理解解析这个值?
I believe the next step should be parse this value in a way the plugin understands?
我可以有一个推吗?
提前致谢,
MEM
Can I have a push please? Thanks in advance, MEM
推荐答案
我想移动到官方支持的jQuery自动完成插件 - 的 http://jqueryui.com/demos/autocomplete/
I would move to the officially supported jQuery autocomplete plugin - http://jqueryui.com/demos/autocomplete/
这实际上是基于关闭你正在使用上述所以它不应该是一个很大的努力来升级插件。以上链接的页面有分析数据的插件远程数据源以及如何详细的例子。
It is actually based off of the plugin you are using above so it should not be a great effort to upgrade. The page linked above has detailed examples of remote datasources and how to parse the data for the plugin.
在一般你想要的来源是一个简单的数组 - 如果你可以修改服务器端的code这将是一个比较理想的返回JSON对象:
In general you want the source to be a simple array - so if you can modify the server-side code this would be a more ideal returning JSON object:
["aaaa.hk","agentesdeexecucao.hk"]
您也可以写一些JavaScript来转换返回的JSON对象到一个单一的阵列。
You could also write some JavaScript to convert the returning JSON objects into a single array.
这篇关于jQuery的自动完成 - 与code帮助 - 何去何从?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!