Git Product home page Git Product logo

autocomplete's People

Contributors

afc163 avatar bitdeli-chef avatar leoner avatar lepture avatar lianqin7 avatar lizzie avatar popomore avatar sorrycc avatar wonderbeyond avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autocomplete's Issues

建议增加focusShow配置

场景:
http://www.aliexpress.com/ 的搜索框

问题:
输入一个字母后离开输入框,再次focus输入框时候需要立即展现之前的联想框体

目前实现:

setup :function() {
    var _self = this;
    xxxxxx.superclass.setup.call(_self);            
    this.get('trigger').focus(function(){
        if(this.value !== "" && _self.get('data').length !== 0){
            _self.show();
        }
    });
}

提供 delay 属性

之前修改了刷新频率的值,但是 ajax 请求发送的还是太频繁,如果设置过长,会有明显的延时。

两者很难折中,所以就提供属性配置。

模版处理数组长度的问题

<div class="{{prefix}}">
    <ul class="{{prefix}}-ctn" data-role="items">
        {{#each items}}
            <li data-role="item" class="{{../prefix}}-item" data-value="{{value}}">{{highlightItem ../prefix}}</li>
        {{/each}}
    </ul>
        {{items.length}}
</div>

items.length 返回为 0

<div class="{{prefix}}">
    <ul class="{{prefix}}-ctn" data-role="items">
        {{items.length}}    
        {{#each items}}
            <li data-role="item" class="{{../prefix}}-item" data-value="{{value}}">{{highlightItem ../prefix}}</li>
        {{/each}}
    </ul>

</div>

items.length 返回正确

测过 handlebars,应该不是这个的问题。

textarea 事件单独处理

textarea 回车的时候是换行而不是提交,submitOnEnter 属性对这种场景意义不大,想想如何对这种场景做特殊处理。

数据源 abort

每次按键都会触发查询流程,现在通过 delay 控制入口,但是如果已经进入数据查询后就不能阻止了。

dataSource 提供 abort 方法可能阻止数据查询,主要是 ajax 的异步查询。

itemSelect 接口变更

现在 callback 返回两个值

.on('itemSelect', function(text, data) {

})

text 的值在 data 中也存在,text 没有存在的必要

blur 隐藏浮层的处理

当选中某一项时,输入框的焦点会移向浮层,这时会触发 blur 事件,blur 优先于 click,浮层隐藏了就无法选中

现在是 400ms 后再触发的处理方式,想想有没有更好的

数据支持复杂的结构

dataSource 获取的数据

[
    {title:'a', name:'b'},
    {title:'c', name:'d'},
]

在选择某项后仍然希望获取 title 和 name,显示和选择的值不同。

支持输入过滤

用户输入的值可能不是 filter 想要的,有时候还要进行处理,增加 inputFilter 参数。

键盘上下的交互

input 框中上下按键会到输入框的最左和最右,如果不阻止感觉体验不好。

textarea 框上下按键是选中不同的行,如果阻止就无法上下移动。

现在 input 默认阻止,textarea 要覆盖的话有很多代码重复。

dataSource 支持 ajax

如果提供的相对路径 / ./ getData.json,用 ajax get 请求

如果为 http:// https:// 则用 jsonp

ajax下filter被重设为空的问题

看到新更新的autocomplete在ajax下把filter拿走了 这个原来作为兼容老接口方案是有用的
例如我们的数据返回需要经过重新组织才能使用。

review 结果

  • ✔ Autocomplete -> AutoComplete

  • ✔ 按照事件命名规范:驼峰

  • ✔ resultsLocator 默认值为 data,用户约定

    resultsLocator 改成任何类型都支持

  • ✘ dataReturn 事件,数据返回的时候可以处理

    filter 处理完后就渲染页面了,没必要再加中间步骤了

  • 参考一下 kissy 的 suggest

  • ✔ 输入框的回车后会提交表单 #2

  • ✔ circular 去掉,默认循环

无数据就不显示了

现在的逻辑是 data 返回空数组就不显示,但有的时候在没数据的时候要显示“无结果”等文案。

希望这种情况只要改模板就好了。

textarea 支持

从 autocomplete 独立出来,textarea-complete.js

  • #12 光标跟随
  • #34 输入框事件处理
  • #36 selectItem 处理
  • #40 上下按键的交互

重构代码

input 变化会触发获取数据、过滤、渲染的流程,选中某项后 input 也发生变化了,但不应该在走这个流程

回车后还是会触发 keyup

keydown 在 keyup 之前,所以回车后还是会触发 keyup,这导致回车选中某项时还会触发 keyup,如果内容有变化还会再次显示。

所以在操作键后不再触发 keyup。

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.