小编ken*_*nji的帖子

Twitter Typeahead.js如何返回字符串中所有匹配的元素

默认情况下,twitter typeahead.js仅返回在字符串开头匹配的元素,例如:

来源:['type','typeahead','ahead']

查询:'类型'

返回:'type'和'typeahead'

-

查询:'提前'

回报:'前进'

我想让它返回'前进'和'打字'

我的代码:

var clients = new Bloodhound({
    datumTokenizer: function(d) { return Bloodhound.tokenizers.whitespace(d.value); },
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    limit: 10,
    prefetch: {
        url: '/clients.json',
        filter: function(list) {
            return $.map(list, function(value) { return { name: value }; });
        }
    }
});

clients.initialize();

$('.client').typeahead(null, {
    displayKey: 'value',
    source: clients.ttAdapter(),
    minLength: 1,
});
Run Code Online (Sandbox Code Playgroud)

已经有一个问题,但我不明白答案.

javascript twitter typeahead typeahead.js

18
推荐指数
1
解决办法
5785
查看次数

如果在验证后我决定将元素移回?如何设置jquery-ui draggable revert为true?

我正在寻找一种方法来从恢复状态触发事件,如果某些事情没有验证,例如,如果元素存在,它将从另一个列表创建它,但如果它已经存在,它应该转到else并将元素返回到它原始位置:

$( "#catalog ul" ).droppable({
        tolerance: 'fit',
        activeClass: "ui-state-default",
        hoverClass: "ui-state-hover",
        accept: ":not(.ui-sortable-helper)",
        drop: function( event, ui ) {
            //check if already exists
            if($(this).find("#"+$(ui.draggable).attr("id")).length==0){
                $( "<li id="+$(ui.draggable).attr("id")+"></li>" ).text( ui.draggable.text() ).appendTo( this )
                .draggable({
                    revert: 'invalid',
                    stop: function(){
                        $(this).draggable('option','revert','invalid');
                    }
                }).droppable({
                    greedy: true,
                    tolerance: 'touch',
                    drop: function(event,ui){
                        ui.draggable.draggable('option','revert',true);
                    }
                });
            }else{
                //want to make the object go back by setting true to revert
                return false;
            }
        }
    })
Run Code Online (Sandbox Code Playgroud)

jquery drag-and-drop jquery-ui

8
推荐指数
1
解决办法
7511
查看次数