CF10 jQuery的自动完成下拉通过用户键入的文本不排序名称 [英] CF10 Jquery Autocomplete drop down names not sorting through the text the user is typing

查看:119
本文介绍了CF10 jQuery的自动完成下拉通过用户键入的文本不排序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我试图找出如何让自动完成正常工作一个CF10功能。当我开始在文本框中键入一个名称查询下删除所有的名字,但没有通过排序以匹配键入的字符。是否与我的searchPhrase和query.term的问题吗?任何人都可以分享一些引导到如何解决文本框只下拉与用户正在输入对应的名称?

 < cffunction NAME =queryNames访问=远程secureJSON =false的>
        < cfargument NAME =searchPhrase>        < CFQUERY NAME =query_names数据源=DSN>
           SELECT CONCAT(assoc_last,'',assoc_first)AS whole_name FROM表
       WHERE assoc_status ='ACTIVE'
    < / CFQUERY>    < CFSET结果= arrayNew(1)>    < CFLOOP查询=query_names>
        < CFSET ArrayAppend(结果,query_names.whole_name)GT;
    < / CFLOOP>    < cfreturn结果>
< / cffunction>

JS

 <脚本类型=文/ JavaScript的>
    $(文件)。就绪(函数(){        $(#名称)。自动完成({
            来源:功能(查询响应){
                $阿贾克斯({
                    网址:重定向/ autocomplete.cfc方法= queryNames和放大器; returnformat = JSON
                    数据类型:JSON
                    数据:{
                        sea​​rchPhrase:query.term
                    },
                    成功:函数(结果){
                        响应(结果);
                    }
                });
            }
        });
    });
< / SCRIPT>

尝试:


        

 < CFQUERY NAME =query_names数据源=DSN>
       SELECT CONCAT(assoc_last,'',assoc_first)AS whole_name FROM表
       WHERE assoc_status ='ACTIVE'
       和assoc_last NOT LIKE'%测试
       和len(assoc_last)GT; 0
       AND(assoc_last像'searchPhrase%
                 或assoc_first像'searchPhrase%')
       ORDER BY assoc_last
    < / CFQUERY>    < CFSET结果= arrayNew(1)>    < CFLOOP查询=query_names>
        < CFSET ArrayAppend(结果,query_names.whole_name)GT;
    < / CFLOOP>    < cfreturn结果>
< / cffunction>


解决方案

这是一个格式化的注释。 做一件事的时间。一旦事情是工作正常,不改变它。

第1步 - 让您的查询工作。如果可能的话,使用数据库客户端做这第一个,那么SQL code复制到ColdFusion的。否则,创建无除了CFQUERY和cfdump标签一个.CFM文件。

第2步 - 让你的查询功能内工作。步骤1将查询到的功能在同一个.CFM文件,并从该页面调用它。此步骤包括传递参数给这个函数。

第3步 - 让你的函数返回预期的结果。你的情况,你想一个数组所以请确保您获得一个。

第4步 - 你的功能复制到CFC和从CFM文件调用它。请确保您设置访问远程

步骤5 - 从JavaScript调用你的函数

I have a CF10 function that I am trying to figure out how to have the autocomplete work properly. When I start typing a name in the text box the query is dropping all the names down but not sorting through to match the characters that are typed. Is there an issue with my searchPhrase and query.term? Can anyone share some guidance into how I can fix the textbox to only drop down the names that correspond with what the user is typing?

<cffunction name="queryNames" access="remote" secureJSON="false">
        <cfargument name="searchPhrase">

        <cfquery name="query_names" datasource="dsn">
           SELECT CONCAT(assoc_last, ' ', assoc_first) AS whole_name FROM table
       WHERE assoc_status = 'ACTIVE'
    </cfquery>

    <cfset result = arrayNew(1) >

    <cfloop query="query_names">
        <cfset ArrayAppend(result, query_names.whole_name)>
    </cfloop>

    <cfreturn result>
</cffunction>

JS

<script type="text/javascript">
    $(document).ready(function() {

        $("#name").autocomplete({
            source: function(query, response) {
                $.ajax({
                    url: "redirects/autocomplete.cfc?method=queryNames&returnformat=json",
                    dataType: "json",
                    data: {
                        searchPhrase: query.term
                    },
                    success: function(result) {
                        response(result);
                    }
                });
            }
        });
    });
</script>

tried:

    <cfquery name="query_names" datasource="dsn">
       SELECT CONCAT(assoc_last, ' ', assoc_first) AS whole_name FROM table
       WHERE assoc_status = 'ACTIVE'
       and assoc_last NOT LIKE 'Test%' 
       and len(assoc_last) > 0 
       AND ( assoc_last like 'searchPhrase%'
                 or assoc_first like 'searchPhrase%')
       ORDER BY assoc_last
    </cfquery>

    <cfset result = arrayNew(1) >

    <cfloop query="query_names">
        <cfset ArrayAppend(result, query_names.whole_name)>
    </cfloop>

    <cfreturn result>
</cffunction>

解决方案

This is a formatted comment. Do one thing at a time. Once something is working properly, don't change it..

Step 1 - get your query to work. If possible, do this with a database client first, then copy the sql code to ColdFusion. Otherwise, create a .cfm file with nothing except cfquery and cfdump tags.

Step 2 - get your query to work inside a function. Put your query into a function on the same .cfm file from step 1 and call it from that page. This step includes passing arguments to that function.

Step 3 - get your function to return the expected results. In your case you want an array so make sure you get one.

Step 4 - copy your function to a cfc and call it from a cfm file. Make sure you set the access to remote.

Step 5 - Call your function from javascript.

这篇关于CF10 jQuery的自动完成下拉通过用户键入的文本不排序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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