Code Monkey home page Code Monkey logo

autocomplete's Introduction

autocomplete


基于Zepto的移动端轻量级Autocomplete组件


使用说明

初始化 autocomplete

var ac = new AutoComplete({
    trigger: '#test',
    dataSource: ['abc', 'abd', 'cbd']
});

API

属性

trigger selector

输入框

parentNode selector

列表容器插入的父节点

template string

默认容器模板

<ul data-role="autocomplete" class="ui-autocomplete"></ul>

itemTemplate string

默认项模板

<li data-role="item" class="ui-autocomplete-item">{{value}}</li>

dataSource array | function(value, done)

数据源

  1. Array

    直接提供数组

    ['abc', 'abb', 'acb']
    
  2. Function

    提供自定义函数,函数提供2个参数,value是当前输入框原始值,done是必须在函数内调用的回调方法,需要传递数组类型数据源,也可以直接返回数据源。

    dataSource: function (value) {
      if (value) {
        var v = value.split('@');
        return dataMaker(v[0], v[1]);
      }
      return [];
    }
    
    var dataSource = ['126.com', '163.com', 'qq.com'];
    
    function dataMaker(prefix, suffix) {
        var data = [];
        $.each(dataSource, function (i, value) {
            if (suffix) {
                if (value.indexOf(suffix) === 0) {
                    data.push([prefix, value].join('@'));
                    return false;
                }
            } else {
                data.push([prefix, value].join('@'));
            }
        });
        return data;
    }
    

autocomplete's People

Contributors

swainet avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.