使用Devbridge Autocomplete,有没有办法检测无结果?

时间:2015-06-10 16:42:27

标签: javascript jquery ajax forms autocomplete

我在输入字段类型文本上使用Devbridge自动填充(https://www.devbridge.com/sourcery/components/jquery-autocomplete)并从数组中读取结果。

有办法:

1)只允许从结果列表中进行选择,而不在字段中输入任何其他内容

2)如果未找到结果,则触发功能

代码:

var people = ['Ross Chapman', 'Curtis Gomez', 'Dolores Gonzales'];

$('.people').autocomplete({
    lookup: people
});

1 个答案:

答案 0 :(得分:2)

您可以将onSearchComplete方法用作mentioned in the docs here

  

onSearchComplete:function(query,suggestions){}

第二个参数建议是在输入中输入字母时的一系列建议。因此,通过检查var people = ['Ross Chapman', 'Curtis Gomez', 'Dolores Gonzales']; $('.people').autocomplete({ lookup: people, onSearchComplete: function (query, suggestions) { if(!suggestions.length){ console.log('no suggestion'); } } }); ,我们可以在advice数组为空时捕获条件,这意味着找不到结果。

JPAQuery bookQuery = new JPAQuery();
QBook qBook = QBook.book;
bookQuery.from(qBook);

BooleanBuilder predicates = new BooleanBuilder();
predicates
        .or(qBook.author.id.eq(personId))              
        .or(qBook.in(
            new JPASubQuery()
                .from(qBook)
                .where(qBook.editor.id.eq(personId)
                .list(qBook)));

bookQuery.where(predicates);

这是一个演示 http://jsfiddle.net/dhirajbodicherla/PSJTQ/21/