jQuery用户界面自动完成 - 多源 [英] Jquery ui autocomplete - multiple sources

查看:125
本文介绍了jQuery用户界面自动完成 - 多源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关1来源,这是AJAX调用后正确的code:
   网址:links2.xml

For 1 source this is the correct code after the ajax call: url: "links2.xml",

我希望源是多个XML文件。我如何包含额外的路径?

I would like the source to be multiple xml files. How do I include the extra paths?

感谢。

推荐答案

首先,在的文档说,自动完成插件预计字符串以指向URL资源,将返回JSON数据。 注意:JSON,而不是XML ,所以你需要将XML转换成JSON在下面。

First of all, the docs say that "the Autocomplete plugin expects that string to point to a URL resource that will return JSON data." Note: JSON, not XML so you need to convert your xml to json in the following.

XML以JSON可以在服务器上或在客户端浏览器来完成。它会更快做一次您的服务器上,如果可能的话。

The xml to json can be done on your server or on the client browsers. It will be faster to do it once on your server, if possible.

要使用多个源文件,则需要先加载在你的HTML / JS页面的多个文件。然后将它们连接在一起成为一个JavaScript数组,然后提供阵列的自动完成呼叫。

To use multiple source files, you will need to first load the multiple files in your HTML/JS page. Then concatenate them together into a Javascript array, then provide the array to the autocomplete call.

是这样的:

<script>
  myproject_choices = []; // global var. Hence prefix with project name.

  var cb = function(data){jQuery.merge(myproject_choices, data);}; // callback for ajax

  $.getJSON('ajax/choices1.json', cb); // fetch and concatenate the choices
  $.getJSON('ajax/choices2.json', cb);
  $.getJSON('ajax/choices3.json', cb);
</script>

# later...
$( ".selector" ).autocomplete({source: myproject_choices });

这篇关于jQuery用户界面自动完成 - 多源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆