npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jq-autosearch

v1.1.0

Published

jquery autosearch autocomplete

Downloads

11

Readme

autosearch

自动搜索 例子见自动搜索框例子 效果图

npm安装

npm install --save jq-autosearch

例1:

<input type="text"  class="autosearch"><input type="hidden" name="hd_id" id="hd_id">
<script src="../src/jquery-1.11.2.js"></script>
<script src="../src/autosearch.js"></script>
<script>
$.get('data.txt',function(result){
	 var input = $('.autosearch');
	 var autosearch = new AutoSearch();
	 autosearch.init({input:input,autoShow:true,data:result,valueObj:'#hd_id',valueName:"id"});
},'json')
</script>

直接的调用,使用静态固定的数据源

例2:

<!-- ajax请求 -->
<input type="text"  class="autosearch2">
<script>
	 var input = $('.autosearch2');
	 var autosearch = new AutoSearch();
	 autosearch.init({input:input ,autoShow:false,data:function(callback){
			$.get('data.txt',{key:input.val()},function(result){
	 		callback(result);
	 		},'json');
 		}
 	});
</script>

数据源会变化

例3:

<!-- 多个 -->
<input type="text"  class="autosearch3">
<script>
$.get('data.txt',function(result){
	 var input = $('.autosearch3');
	 var autosearch = new AutoSearch();
	 autosearch.init({input:input,autoShow:false,data:result,mutil:true
	 	});
},'json')
</script>

属性

input: [DOM]

输入框,jquery DOM对象

data:[obj|function]

数据源,这里可以传入数据源数组,也可以传入一个方法作为回调返回数据,如果传入的是数组,将作为静态过滤筛选,如果是传入的方法,每次都会调用该方法进来过滤。

autoShow:[bool]

是否在获得焦点时就显示数据,默认为false

valueObj:[DOM]

赋值框,jquery DOM对象

filterColumn:[array string]

过滤的字段列,默认为['name'],可以同时对多个数据列过滤

column:[array string]

显示的列,默认为['name'],如果想定义显示项,可以配置回调方法format:function(item)来返回显示内容

mutil:[bool]

选多个,默认为false

min:1

最少几个字符开始搜索

valueName:name

要显示在列表里的值.

回调方法

callback :function(data)

选中的回调,data为当前选中的数据项.可以用于扩展选中后的显示效果

focusCallback:function(input)

获取焦点

blurCallback:function(input)

离开焦点

showCallback:function(input,content)

显示后的回调

resetCallback:function(input)

this,没选择的重置回调