开发者

Coldfusion stripping leading zeroes in autosuggest

I've just encountered CF's unwanted "feature" which involves stripping leading zeroes from the values returned to an autosuggest input. I was thinking I could prepend some character to the values and strip them out after the return, but have hit a snag. I'm modifying an existing function, which looks like this:

<cffunction name="lookupTailNumber" access="remote" returntype="Array" >
    <cfargument name="search" type="any" required="false" default="">
    <!--- Define variables --->
    <cfset var data="">
    <cfset var result=ArrayNew(1)>

    <!--- Do search --->
    <cfquery name="data">
        SELECT DISTINCT SERIAL_NUMBER AS list
        FROM aircraft_status
        WHERE SERIAL_NUMBER LIKE '%#trim(ARGUMENTS.search)#%'
        ORDER BY list
    </cfquery>

    <!--- Build result array --->
    <cfloop query="data">
        <cfset ArrayAppend(result, list)>
    </cfloop>

    <!--- And return it --->
    <cfreturn result>

</cffunction>

which returns a response which looks like this:

[3001.0,1.00002E8,1.00002001E8,1.00002002E8,1.00002003E8,1.00002004E8]

or in JSON format:

0 3001

1 100002000

2 100002001

3 100002002

4 100002003

where all the results have had leading zeroes stripped away. I've tried modifying the query to prepend a character to each value:

<cfquery name="data">
        SELECT DISTINCT (concat(' ', SERIAL_NUMBER)) A开发者_如何转开发S list
        FROM aircraft_status
        WHERE SERIAL_NUMBER LIKE '%#trim(ARGUMENTS.search)#%'
        ORDER BY list
    </cfquery>

which returns this:

[" 0000003001"," 0100002000"," 0100002001"," 0100002002"," 0100002003"," 0100002004"]

so you'd think all was well, right? Problem: when returned, none of the values show up in the autosuggest field!!! I've also tried prepending different characters, including numbers, with no luck. Looking at the elements in yui-ac-bd div > ul, none are populated or displayed.

The input is declared like so:

<cfinput style = "width:300px;"
                     class = ""
                     type="text"
                     name="txtvalueFilter"
                     maxlength="15"
                     id="txtvalueFilter"
                     autosuggest="cfc:mycfcpath({cfautosuggestvalue})"
            />

Thoughts?


Try appending a space, so the built-in JSON serializer will treat it as a string instead of an int in JSON.

Also, make sure you have installed the latest hotfixes for your version of CF.

I wonder if u need to "Build result array". What happen if you return data.list? or, maybe use ListToArray(valueList(data.list)) instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜