【问题标题】:jquery auto complete with multiple parameters in JSPjQuery在JSP中使用多个参数自动完成
【发布时间】:2012-05-05 18:47:08
【问题描述】:

我使用 JSP,我想传递两个参数以及 jquery 自动完成功能。我的第二个参数是选择框的值。我使用了以下代码,但只获得了选项中的第一个值。我检查了返回选择框值的函数,它只在页面加载时被调用。有什么办法可以解决我的问题吗?

 /* inside my page */


        jQuery(function() {
    $("#branch").autocomplete("getbranchdetails.jsp", {
        extraParams: {
            filter: getDropdownValue()
        }
    });
});


    function getDropdownValue() {
    var compId=document.getElementById("company").value;
    return compId;
    }




        /* inside getbranchdetails.jsp */

        <%
        String company=request.getParameter("filter");

        System.out.println("company :"+company);


        getbranchdetails db=new getbranchdetails();
        String query = request.getParameter("q");
        List<String> agent = db.getData(query,brtype);
        Iterator<String> iterator = agent.iterator();
        while(iterator.hasNext()) {
        String agents = (String)iterator.next();
        out.println(agents);
        }
        %>

我也尝试了以下链接,但没有运气 http://123code.blogspot.in/2010/09/jquery-autocomplete-plugin-using.html

【问题讨论】:

    标签: jquery jsp autocomplete drop-down-menu url-parameters


    【解决方案1】:

    改变这个:

    $("#branch").autocomplete("getbranchdetails.jsp");
    extraParams: {
        filter: getDropdownValue()
    }
    }); 
    

    $("#branch").autocomplete("getbranchdetails.jsp", {
        extraParams: {
            filter: getDropdownValue()
        }
    });
    

    【讨论】:

    • 感谢 Mark Schultheiss,这是我在这里输入的错误。我现在在问题中对其进行了编辑。
    • @arjuncc - 您的问题目前并未反映带有额外括号的陈述。
    • 不,您的问题仍然存在:"getbranchdetails.jsp"),{ 看到那个右括号,就在那个逗号之前?从我的答案中复制确切的代码并尝试一下。
    • 查看这两个代码片段的小提琴,单击 jslint 按钮查看错误。 jsfiddle.net/fZwyK/1
    【解决方案2】:

    看看这个 jsFiddle...http://jsfiddle.net/PTeMy/

    在自动完成中,源可以定义为函数调用。使用它,您应该能够根据需要构建自动完成列表。

    例如...

    HTML

    <input id="auto" type="text">
    
    must contain....
    <select>
        <option value="a">a</option>        
        <option value="b">b</option>        
        <option value="c">c</option>        
        <option value="d">d</option>        
        <option value="e">e</option>        
        <option value="f">f</option>        
        <option value="g">g</option>        
    </select>​
    

    脚本

    $(document).ready(function(){
        $('#auto').autocomplete({
            source: getTags()
        });
    });
    
    function getTags(){
            var tags = [
                "ActionScript",
                "AppleScript",
                "Asp",
                "BASIC",
                "C",
                "C++",
                "Clojure",
                "COBOL",
                "ColdFusion",
                "Erlang",
                "Fortran",
                "Groovy",
                "Haskell",
                "Java",
                "JavaScript",
                "Lisp",
                "Perl",
                "PHP",
                "Python",
                "Ruby",
                "Scala",
                "Scheme"
            ];   
    
        tags = $.grep(tags, function(t) {
            return t.indexOf($('select').val()) > 0;
        });
    
        return tags;
    }
    
    ​
    

    【讨论】:

    • OP 使用的是插件,而不是 jQuery UI 自动完成。
    • 对不起...错过了。我会发布另一个答案。
    【解决方案3】:

    试试这个...

    $('#branch').autocomplete('getbranchdetails.jsp', {
        mustMatch: false
    });
    
    $('#branch').setOptions({
        extraParams:{filter: function(){return $('#company').val();}
    });
    

    【讨论】:

      猜你喜欢
      • 2013-03-19
      • 2013-08-19
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 2018-07-23
      • 2012-06-13
      • 1970-01-01
      • 2017-10-23
      相关资源
      最近更新 更多