3 Star 1 Fork 0

Gitee 极速下载/AutoComplete

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/commadelimited/autoComplete.js
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

autoComplete.js

AutoComplete is a jQuery Mobile plugin which allows developers to add autoComplete search boxes to your project.

Based on the blog entry of Raymond Camden (@cfjedimaster).

Example

View a simple demo of autoComplete

Quick start

Clone the git repo - git clone https://github.com/commadelimited/autoComplete.js.git - or download it

Usage & Documentation

$("#searchField").autocomplete({
	method: 'GET', // allows POST as well
	icon: 'arrow-r', // option to specify icon
	target: $('#suggestions'), // the listview to receive results
	source: 'data.cfc?method=search&returnformat=json', // URL return JSON data
	callback: fn(){}, // optional callback function fires upon result selection
	link: 'target.html?term=', // link to be attached to each result
	minLength: 0 // minimum length of search string
	transition: 'fade',// page transition, default is fade
	matchFromStart: true, // search from start, or anywhere in the string
	loadingHtml : '<li data-icon="none"><a href="#">Searching...</a></li>', // HTML to display when searching remotely
	interval: 0, // The minimum delay in milliseconds between server calls when using a remote "source"
	builder : null, // optional callback to build HTML for autocomplete
	labelHTML: fn(){}, // optional callback function when formatting the display value of list items
	onNoResults: fn(), // optional callback function when no results were matched
	onLoading: fn(), // optional callback function called just prior to ajax call
	onLoadingFinished: fn(), // optional callback function called just after ajax call has completed
	dataHandler : fn(), // optional function to convert the received JSON data to the format described below
	klass: 'tinted', // optional class name for listview's <li> tag
	forceFirstChoiceOnEnterKey : true, // force the first choice in the list when Enter key is hit
	transformResponse: fn() //transform your data into useable data to create autoComplete items list, return json obect with
				// label and value attribute e.g. {label : "text to show", value: "hidden value"}
});

AutoComplete can access local arrays or remote data sources.

AutoComplete.js can read data in one of two ways: simple or complex. Simple data should be returned from the source in the following format:

[
	"Maine",
	"Maryland",
	"Massachusetts"
]

Causing the resulting code to look like this: <a href="target.html?term=Maine">Maine</a>

Complex data allows developers to specify which value goes where. This option requires data to be returned as an array of objects:

[
	{
		value: "22",
		label: "Maine"
	},
	{
		value: "23",
		label: "Maryland"
	},
	{
		value: "24",
		label: "Massachusetts"
	}
]

Causing the resulting code to look like this: <a href="target.html?term=22">Maine</a>

Data-autocomplete attribute

In 1.4.3 a new "data-autocomplete" property was added to the anchor tag contained with each list item. This attribute contains a serialized version of each item in the array. See "callback-plus.html" for usage.

Callback

When using the optional callback function autoComplete will only execute code found within the callback. The click event object is passed into the callback function for use in accessing the information contained in the selection. Here's one use case:

$("#searchField").autocomplete("update", {
	source: [ "foo", "bar", "baz" ],
	minLength: 3,
	callback: function(e) {
		var $a = $(e.currentTarget); // access the selected item
		$('#searchField').val($a.text()); // place the value of the selection into the search box
		$("#searchField").autocomplete('clear'); // clear the listview
	}
});

Utility Methods

update - takes an object containing AutoComplete settings to update

This method allows you to update AutoComplete settings for an element after the plugin has been initialized.

$("#searchField").autocomplete("update", {
	source: [ "foo", "bar", "baz" ],
	minLength: 3
});

clear

This method will clear the "target" listview. Useful if you need to empty the list in response to other events.

$("#searchField").autocomplete("clear");

destroy

This method will clean up any bound events or data stored on the element.

$("#searchField").autocomplete("destroy");

Events

targetUpdated.autocomplete

Event fired each time the target listview is updated. A potential use is to bind to this event and scroll to the top of the page so that the list of completions is not completely hidden behind the soft/virtual keyboard.

$("#searchField").autocomplete({
	target: $('#autocomplete'),
	source: autocompletes
}).bind("targetUpdated.autocomplete", function(e) {
	$.mobile.silentScroll($(e.currentTarget).offset().top);
});

targetCleared.autocomplete

Event fired when the target listview is emptied (no completions to display).

Contributing

You are invited to contribute code and suggestions to this project. The more the merrier.

Project Info

3rd party libraries required:

  • jQuery: MIT/GPL license
  • jQuery Mobile: MIT/GPL license

Custom bits:

MIT/GPL license

Bitdeli Badge

Copyright (c) 2012 andy matthews Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

AutoComplete 是一个 jQuery Mobile 的插件,用于实现在 jQuery Mobile 中的搜索框中提供自动完成的功能 展开 收起
README
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/AutoComplete.git
git@gitee.com:mirrors/AutoComplete.git
mirrors
AutoComplete
AutoComplete
master

搜索帮助