如果没有结果与密钥匹配,则显示所有项目

时间:2016-12-07 13:58:06

标签: jquery jquery-ui jquery-ui-autocomplete

在JQuery auto complete中,如果没有与输入的键匹配,我想显示所有结果。另外,我需要将minLength限制为 3

这是我的代码。我已检查ui.content.length === 0并触发了$(this).autocomplete('search', $(this).val()),但它无效。

$( "#example" ).autocomplete({
      source: availableTags,
      minLength:3,
      response: function(event, ui) {
        if (ui.content.length === 0) {
          $(this).autocomplete('search', $(this).val())
        }
      }
});

1 个答案:

答案 0 :(得分:1)

这是一个潜在的解决方案:

library(dplyr)

# A minimal example
df1 <- data.frame(a=factor(letters), b=1:26)
df2 <- data.frame(a=1:10, b=factor(letters[1:10]))
dfl <- list(df1,df2)

# This would generate your error
# df <- bind_rows(dfl)

# This would solve it while keeping the factors
df <- dfl %>%
      lapply(function(x) mutate_each(x, funs('as.character'))) %>%
      bind_rows() %>% 
      mutate_each(funs('as.factor'))

工作示例:https://jsfiddle.net/Twisty/7gpLtq6c/

如果它为空,我们只是将所有可能的结果推回到数组中。

相关问题