Coldfusion自动建议在字符串中间不起作用 [英] Coldfusion autosuggest not working for suggestions in the middle of the string

查看:64
本文介绍了Coldfusion自动建议在字符串中间不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的自动建议,我正在使用下面的代码。

For my autosuggest I'm using the code below.

键入时,它只会查找字符串的开头。
例如,如果我输入 abcd,它将带有建议 abcde ...。

When typing, it only looks at the beginning of the string. For example if I type 'abcd' it will come with suggestions 'abcde...' that is good.

但是它没有做什么,如果我键入 def,并且在数据库中有一个字符串 abcdefg,那么它就不会出现在自动提示中。

But what it doesn't do, if I type 'def' and in the database I have a string 'abcdefg' then this doesn't come in the autosuggest.

在我的查询中,我确实有百分比在搜索字符串前后的字符。

In my query I do have the percent characters infront and behind the search string.

对我来说,似乎自动提示仅查看在开头而不是在中间键入的字符。

So to me it looks like the autosuggest only looks at the characters typed at the beginning, not in the middle.

还是我做错了什么?

<cfcomponent output="false">

    <cffunction name="lookupJobs" access="remote" returntype="array">
       <cfargument name="search" type="any" required="false" default="">

       <cfset var qGetJobs="">
       <cfset var result=ArrayNew(1)>
       <cfquery name="qGetJobs" datasource="#application.dsn#"> 
          SELECT DISTINCT title
          FROM tbl_jobs  
          WHERE  title LIKE '%#arguments.search#%' 
          ORDER BY title
       </cfquery> 
       <cfloop query="qGetJobs">
           <cfset ArrayAppend(result, title)>
       </cfloop>
       <cfreturn result>
    </cffunction>

</cfcomponent>


推荐答案

感谢Leigh,解决方案是使用cfinput。

Thanks to Leigh, the solution was with the cfinput.

<cfinput type="text" name="title" 
      showautosuggestloadingicon="false"
      autosuggest="cfc:autosuggest.lookupJobs({cfautosuggestvalue})"   
      matchContains="true">

我需要添加属性: matchContains = true

这篇关于Coldfusion自动建议在字符串中间不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆