使用AJAX的jQuery自动完成标签插件

时间:2023-01-14 11:04:00

I am looking for good tags autocomplete plugin with Ajax. Currently i am working with http://timschlechter.github.io/bootstrap-tagsinput/examples/ but i need to get data from ajax query not from json file. Is it even possible? All the plugins that i've seen got data from array in json file. I need to search data dynamically directly from the database. Something like * tags input, i suppose.

我正在寻找带有Ajax的好标签自动完成插件。目前我正在使用http://timschlechter.github.io/bootstrap-tagsinput/examples/但我需要从ajax查询中获取数据而不是从json文件中获取数据。它甚至可能吗?我见过的所有插件都从json文件中的数组中获取数据。我需要直接从数据库中动态搜索数据。我猜想像*标签输入之类的东西。

2 个解决方案

#1


0  

Look into jquery UI autocomplete, especially the remote data source example.

查看jquery UI自动完成,尤其是远程数据源示例。

You can directly specify a remote data source which returns data in either of the below formats like:

您可以直接指定远程数据源,该数据源以下列任一格式返回数据,如:

$( "#birds" ).autocomplete({
  source: "search.php" // url to remote source
});

The data source should return data in any of the following formats:

数据源应以以下任何格式返回数据:

  • An array of strings: [ "Choice1", "Choice2" ]
  • 字符串数组:[“Choice1”,“Choice2”]

  • An array of objects with label and value properties:

    具有label和value属性的对象数组:

    [ { label:"Choice1", value: "value1" }, ... ]
    

#2


0  

Ok, i solved my problem. I used bootstrap-tagsinupt plugin, jquery get() function, also i used json_encode to parse the data from array.

好的,我解决了我的问题。我使用了bootstrap-tagsinupt插件,jquery get()函数,我还使用了json_encode来解析数组中的数据。

#1


0  

Look into jquery UI autocomplete, especially the remote data source example.

查看jquery UI自动完成,尤其是远程数据源示例。

You can directly specify a remote data source which returns data in either of the below formats like:

您可以直接指定远程数据源,该数据源以下列任一格式返回数据,如:

$( "#birds" ).autocomplete({
  source: "search.php" // url to remote source
});

The data source should return data in any of the following formats:

数据源应以以下任何格式返回数据:

  • An array of strings: [ "Choice1", "Choice2" ]
  • 字符串数组:[“Choice1”,“Choice2”]

  • An array of objects with label and value properties:

    具有label和value属性的对象数组:

    [ { label:"Choice1", value: "value1" }, ... ]
    

#2


0  

Ok, i solved my problem. I used bootstrap-tagsinupt plugin, jquery get() function, also i used json_encode to parse the data from array.

好的,我解决了我的问题。我使用了bootstrap-tagsinupt插件,jquery get()函数,我还使用了json_encode来解析数组中的数据。