![](/img/trans.png)
[英]Reading selected value from struts2 jquery autocompleter using javascript
[英]How to reload the struts2-jquery autocompleter X with value selected from another struts2-jquery autocompleter Y
我的jsp頁面中有兩個名為x,y的strut2 Jquery自動完成器框。 如果我更改了x,則y也應根據x的選定值自動更改。在struts dojo標簽中,我使用了監聽主題來重新加載。 但是strut2 jquery無法重新加載。
我的密碼
<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自動完成程序列出其中一項,則可以執行以下操作:
將第一個on的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);
其中setJQueryAutocompleterURL是另一個函數
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);
}
然后,您將擁有extraparameter作為json調用的參數來過濾結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.