如何更改Struts2自动完成程序的来源?

时间:2018-07-26 17:29:12

标签: jquery autocomplete struts2

因此,我已经使用struts2标签制作了一个自动完成界面。即“ sj:autocompleter”

我需要在keyup上更改自动完成程序的来源。我首先给出前100个结果,然后在keyup函数上我希望源动态变化。我该如何实现?

这是我的自动放大标签

<sj:autocompleter name="locationName" selectBox="true"
     selectBoxIcon="true" 
     requiredLabel=""
     id="USER_NAME" autocomplete="off"
     tabindex="%{session.fielddata.USER_NAME.getSearchFilterSequence()}"
     label="%{session.fielddata.USER_NAME.getFieldLabel()}"
     parentTheme="xhtml" labelSeparator=""
     list="session.initialUserListForDropDown"
     value="%{session.searchcriteria.locationName}"
     cssClass="pointercursor  resetfields"
     style="border-radius:3px;"
     maxLength="%{session.fielddata.USER_NAME.getFieldMaxValue()}">
 </sj:autocompleter>

下面是我绑定的键盘功能

setTimeout(function(){
    $(".form-group.username").find(".s2j-combobox-input.ui-autocomplete-input").keyup(function(event){
        var userNameSearch= $(this).val();
        if(event.which!=37 && event.which!=38 && event.which!=39 && event.which!=40 && event.which!=13)
        {
            var options_USER_NAME_widget = {};
            options_USER_NAME_widget.hiddenid = "USER_NAME";
            options_USER_NAME_widget.selectBox = true;
            options_USER_NAME_widget.selectBoxIcon = true;
            options_USER_NAME_widget.forceValidOption = true;
            options_USER_NAME_widget.jqueryaction = "autocompleter";
            options_USER_NAME_widget.id = "USER_NAME_widget";
            options_USER_NAME_widget.name = "locationName_widget";
            options_USER_NAME_widget.href = "applicationURL+"searchUserNameValues"+"?"+"userNameSearch"=userNameSearch

            jQuery.struts2_jquery_ui.bind(jQuery('#USER_NAME_widget'),options_USER_NAME_widget);
        }
        });
    },1000);

这是我的JSON

{"searchedUserNames":["","admin","abcd","undertaker","hellya","ohno","grand","supp","oimate","cmom","sgray","jlambregtse","ssantana","jharris","cmanroy","lololo","abhi","bc","mc","di","admin1","admin2","admin3","adm2in","yoyo","BackendUser","hello"]}

此JSON正以字符串形式存储在select中..我在做什么错?我该如何工作?

我也尝试通过打击代码设置源,但是它不起作用

$(".form-group.username").find(".s2j-combobox-input ui-autocomplete-input").autocomplete( "option", "source", list );

0 个答案:

没有答案