【问题标题】:Jqueryui autocomplete w/ Django - is there a way to autocomplete only after special characters?带有/ Django的Jquery Ui自动完成 - 有没有办法只在特殊字符后自动完成?
【发布时间】:2014-02-08 00:56:56
【问题描述】:

我不认为我以前见过这样做,所以我不确定它是如何工作的。我想使用 jqueryui 从我的模型中获取自动完成值 - 但仅在输入左括号字符时。

例子:

输入城市名称,然后在括号中输入其所在州。

奥尔巴尼(纽约)

来源是州

^ 我正在寻找一种让纽约弹出的方式,这将是“州”模型的一个实例,一旦输入“(”然后输入“n”。我什至不确定哪个部分框架将反映这一点。

【问题讨论】:

    标签: django jquery-ui autocomplete


    【解决方案1】:

    看来这应该对你有所帮助。

    这是基于官方jqueryui autocomplete example,我对最相关的部分做一点评论:

    $( "#tags" ).autocomplete({
      source: function( request, response ) {
        // use only the string after "(" to compare against the example array. 
        response($.ui.autocomplete.filter(availableTags, request.term.slice(request.term.indexOf("(") + 1)));
      },
    
      search: function( event, ui ) {
        var input = event.target.value;
    
        // don't trigger autocomplete until "(" is present.
        if(input.indexOf('(') !== -1) {
          return true;
        }
    
        return false;
      },
    
      select: function( event, ui ) {
        var input = event.target.value;
    
        // return the inputted string + selected value, instead of just selected value alone
        ui.item.value = [input.slice(0, input.indexOf("(") + 1), ui.item.label].join("");
      }
    });
    

    【讨论】:

    • 非常感谢,帮了大忙!
    猜你喜欢
    • 1970-01-01
    • 2017-02-08
    • 2013-10-10
    • 2015-09-14
    • 2021-05-27
    • 2011-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多