Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery";“自动完成”;不';行不通_Jquery_Jquery Ui_Jsf 2_Autocomplete - Fatal编程技术网

jQuery";“自动完成”;不';行不通

jQuery";“自动完成”;不';行不通,jquery,jquery-ui,jsf-2,autocomplete,Jquery,Jquery Ui,Jsf 2,Autocomplete,JQuery自动完成代码似乎是正确的,但不起作用 代码似乎很简单,我在IE8中使用“开发者工具”或FireFox中的“firebug”工具时没有看到任何javascript错误 但是,当在输入字段中键入字母(如“a”)时,列表框中不会“下拉”任何内容 如果你觉得有什么不对劲,请告诉我。很明显,我现在并不是在“见林不见树” 以下是JSF“复合组件”定义中的片段。… 谢谢你的帮助 sd该代码是否被调用?这段代码似乎有点多余。我怀疑传递给内部jq的函数是否被调用过。如果确实不是,则永远不会初始化自动

JQuery自动完成代码似乎是正确的,但不起作用

代码似乎很简单,我在IE8中使用“开发者工具”或FireFox中的“firebug”工具时没有看到任何javascript错误

但是,当在输入字段中键入字母(如“a”)时,列表框中不会“下拉”任何内容

如果你觉得有什么不对劲,请告诉我。很明显,我现在并不是在“见林不见树”

以下是JSF“复合组件”定义中的片段。…

谢谢你的帮助


sd

该代码是否被调用?这段代码似乎有点多余。我怀疑传递给内部
jq
的函数是否被调用过。如果确实不是,则永远不会初始化自动完成。您可以通过添加断点进行验证,或者在调用
jq(comboid)前后放置一个警报。自动完成
如果您收到两个警报,那么该行也将被执行(可能是使用了错误的元素)


似乎有两个问题(即,作为jquery新手)的组合。

<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:util="http://java.sun.com/jsf/composite/util"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <f:view contentType="text/html">
        <h:head>
            <title>testx</title>
            <meta charset="utf-8" />
        </h:head>
        <h:body prependid="false">
            <h:form id="form1" prependId="false">
                <util:autoComplete prependId="false"
                                   idpref="aaa"
                                   items="#{refDataController.data}" />
            </h:form>
        </h:body>
    </f:view>
</html>


    package aaa.bbb.ccc.war;

    import java.util.Arrays;
    import java.util.List;
    import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Component;

    @Component("refDataController")
    @Scope("request")
        public class RefDataController
        {
            public RefDataController()
            {
            }
            private List data = Arrays.asList    ("\"Aman\"", "\"Albela\"", "\"Ali\"", "\"Ankit\"", "\"Azam\"", "\"Aryan\"");
            public List getData()
            {
                return data;
            }
        }

问题#1。一个有点尴尬的疏忽(阿拉,“你的电脑插上电源了吗?”)。。。我将autocomplete函数的“minLength”参数值设置为3,并且没有键入至少3个字符,因此在最初测试时没有显示列表(我删除了此参数,目前使用默认的最小长度1)

第2期。然而,主要的问题是我不理解jquery选择器在JSF冒号(“:”)字符方面存在的问题。我使用两种解决方法之一解决了这个问题(通过谷歌搜索信息等):

(注意:在这些代码片段中,“{cc.attrs.idpref}”是JSF“复合组件”属性用于指定元素id…FWIW,在这种情况下,值恰好是“aaa”)

解决方法#1

//get the full id value of the element whose "id ends with" aaa...
var id = jq('input[id$="' + "#{cc.attrs.idpref}" + '"]').attr("id");
//"escape" the colon character so that jquery will not be confused...
id = id.replace(/:/g,"\\:");
//used escaped id value in the selector...
jq("input#" + id).autocomplete({
   source: list
});
//start with the **unprepended** id value specified in the composite component  attribute...
var id = "#{cc.attrs.idpref}";
// use the "id ends with" aaa selector with the autocomplete function... 
jq('input[id$="' + "#{cc.attrs.idpref}" + '"]').autocomplete({
   source: list
});
解决方法#2

//get the full id value of the element whose "id ends with" aaa...
var id = jq('input[id$="' + "#{cc.attrs.idpref}" + '"]').attr("id");
//"escape" the colon character so that jquery will not be confused...
id = id.replace(/:/g,"\\:");
//used escaped id value in the selector...
jq("input#" + id).autocomplete({
   source: list
});
//start with the **unprepended** id value specified in the composite component  attribute...
var id = "#{cc.attrs.idpref}";
// use the "id ends with" aaa selector with the autocomplete function... 
jq('input[id$="' + "#{cc.attrs.idpref}" + '"]').autocomplete({
   source: list
});
谢谢大家的集体回复


sd

我将在“jq(comboid).autocomplete”前后输入2个警报…--稍后给您回复。thanksI在“自动完成”之前和之后添加了警报,并且在进入或刷新页面时都会显示警报。这确实是一种奇怪且不必要的方法,但它可以工作。此外,
prepended
comboid
变量赋值方法也很奇怪,没有必要。为什么不直接使用
jq('input[id$=“'+id+'”)。自动完成(…)
呢?我删除了“jq(function()”,得到了相同的结果-两个警报都显示出来。我想我会忽略它们。仍然没有得到任何“dropdown”列表,并且找到了combo元素?jq(comboid)的长度是多少?它应该是1。