将查询结果数组传递给jQuery Autocomplete源属性 [英] Passing array of query results to jQuery Autocomplete source attribute
问题描述
尝试将查询结果传递到jquery autocomplete的来源属性时,我遇到了一个问题...
I'm struck up with an issue when tried to pass the query results to the jquery autocomplete's source attribute...
<cfloop query="MyQuery">
<cfset head=#ValueList(MyQuery.pname,",")#>
<cfset head1=#listtoarray(head)#>
</cfloop>
这里我想将head1数组发送到jquery代码,
Jquery自动完成代码如下。
Here I want to send the head1 array to the jquery code, Jquery autocomplete code goes as follows..
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
var availableTags = head1;
$("#k").autocomplete({
source:availableTags
});
});
</script>
</cfif>
如何将head1传递给availableTags
How to pass head1 to the availableTags
推荐答案
首先,
你的cfloop只是运行 valuelist
和 listtoarray
一遍又一遍,结果相同。在查询循环中没有意义。请参阅 valueList 的详细资料
First,
your cfloop is doing nothing but running valuelist
and listtoarray
over and over with the same results. There's no point in putting that in a query loop. See the details on valueList
你可以在你的CF中做这样的事情:
You can simply do something like this in your CF:
<cfset head=#ValueList(MyQuery.pname,",")#>
<cfset head1=#listtoarray(head)#>
ColdFusion有一个很好的函数 toScript
ColdFusion has a nice function called toScript that
创建JavaScript或ActionScript表达式,将ColdFusion变量的值
分配给JavaScript或ActionScript变量。
此函数可以转换ColdFusion字符串,数字,数组,
结构,并查询JavaScript或ActionScript语法
定义等效变量和值。
Creates a JavaScript or ActionScript expression that assigns the value of a ColdFusion variable to a JavaScript or ActionScript variable. This function can convert ColdFusion strings, numbers, arrays, structures, and queries to JavaScript or ActionScript syntax that defines equivalent variables and values.
要使用CF数组创建JS数组,您可以执行以下操作:
To create your JS array using your CF array you can do the following:
$(function() {
<cfoutput>var #ToScript(head1, "availableTags")#;</cfoutput>
$("#k").autocomplete({
source:availableTags
});
});
toScript的输出看起来像
The output of toScript looks something like
var availableTags = new Array();
availableTags[0] = "something";
availableTags[1] = "something else";
availableTags[2] = "another something";
availableTags[3] = "even more something";
这篇关于将查询结果数组传递给jQuery Autocomplete源属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!