如何用从另一个struts2 jquery自动补全器Y中选择的值重新加载struts2 jquery自动补全机X

How to reload the struts2-jquery autocompleter X with value selected from another struts2-jquery autocompleter Y

本文关键字:jquery struts2 新加载 加载 全机 另一个 何用 选择      更新时间:2023-09-26

我的jsp页面中有两个名为x,y的strut2Jquery自动补全框。如果我更改x,那么y也应该根据x的选定值自动更改。在struts dojo标记中,我使用侦听主题来重新加载。但是strut2jquery无法重新加载。

我的代码

             <sj:autocompleter
                id="mapNameList"
                name="map_name"
                list="%{mapNameList}"
                selectBox="true"
                selectBoxIcon="true"
                onChangeTopics="autocompleteChange"
                onFocusTopics="autocompleteFocus"
                onSelectTopics="autocompleteSelect"
                />
        <label for="map_type">MapType: </label>
            <sj:autocompleter
                id="mapTypeList"
                name="map_type"
                list="%{mapTypeList}"
                selectBox="true"
                selectBoxIcon="true"
                onChangeTopics="autocompleteChange"
                onFocusTopics="autocompleteFocus"
                onSelectTopics="autocompleteSelect"
                />

如果你更喜欢json自动补全器来列出一个你可以做的:

将第一个的onSelectTopics定义为特定值,如

onSelectTopics="/mapNameListChange"

为第二个定义

listenTopics="/mapNameListChange"

创建一个类似于的函数

$.subscribe("/mapNameListChange",function(event, data){
            //clear the children autocompleters
            jQuery('#mapTypeList').val("");
            jQuery('#mapTypeList_widget').val("");
            var ui = event.originalEvent.ui;
            if (ui.item && ui.item.value.length > 0) {
                setJQueryAutocompleterURL(jQuery('#mapTypeList_widget'),"your json request", "extraparameter=" + ui.item.value, "the list used in the json", "mapTypeList", "map_type", "/mapNameListChange", "/mapTypeListChange");
            };
        },null);

其中setJQueryAutocompleteURL是另一个函数

function setJQueryAutocompleterURL(widget,href, hrefparameter, list, id, name, selectTopics, listenTopics) {
        var options_auto_iban_widget = {};
        options_auto_iban_widget.hiddenid = "mapTypeList";
        options_auto_iban_widget.selectBox = true;
            options_auto_iban_widget.selectBoxIcon= true;
        options_auto_iban_widget.forceValidOption = true;
        options_auto_iban_widget.onselecttopics = "/autoDebtorIbanChange";
        options_auto_iban_widget.list = list;
        options_auto_iban_widget.listkey = "id";
        options_auto_iban_widget.listvalue = "name";
        options_auto_iban_widget.jqueryaction = "autocompleter";
        options_auto_iban_widget.id = id;
        options_auto_iban_widget.name = name + "_widget";
        options_auto_iban_widget.href = href+"?"+hrefparameter;
        options_auto_iban_widget.listentopics = "/autoDebtorBicChange"; 
        jQuery.struts2_jquery_ui.bind(widget,options_auto_iban_widget);
    }

然后,您将获得一个外部参数作为json调用的参数来过滤结果。