3

工作(加载列表很好):

<s:url id="countrylist" action="lstcountryaction" />
<sj:autocompleter list="lstcountry"
    listKey="idcountry" listValue="countryname" label="Country"
    href="%{countrylist}" name="idcountry" />

不起作用(没有加载任何内容。没有调用该操作):

<s:url id="countrylist" action="lstcountryaction" />
<sj:autocompleter selectBox="true" list="lstcountry"
    listKey="idcountry" listValue="countryname" label="Country"
    href="%{countrylist}" name="idcountry" />

唯一的区别是selectBox添加了属性。我错过了什么?我正在使用 Struts 2.3.15 和 Struts2 JQuery Plugin 3.6.1(它们都是相当新的)。

谢谢 !!

4

2 回答 2

2

+1 因为我看到你已经在相关的 Google Group 上发帖了......但是,如果同时没有改变,根据插件作者的这个(很旧,但仍然打开 JIRA)评论:

带有 selectBox 的自动完成器正在使用静态列表。在您的用例中,您应该使用<sj:select />带有 autocomplete="true" 的标签。

<s:url id="remoteurl" action="jsonsample"/> 
<sj:select
         href="%{remoteurl}"
         autocomplete="true"
         id="echo3"
         name="echo"
         list="languageObjList"
         listKey="myKey"
         listValue="myValue"
         emptyOption="true"
         headerKey="-1"
         headerValue="Please Select a Language"/>

然后一个<sj:select />with both emptyOptionand autocompleteset totrue可以替代<sj:autocompleter />您正在寻找的动态选择框。

也可以随意运行这个示例,这似乎是开箱即用的。

于 2013-12-19T00:02:33.910 回答
2

启用了能够正常工作的 Struts2 jQueryautocompleter小部件不应远程加载数据。selectBox=true换句话说,该属性href="%{countrylist}"是选择框不起作用的罪魁祸首。这两个属性是互斥的。您必须在两个选项之间进行选择,要么使用autocompleter带有远程数据的作为输入框,要么作为选择框但不远程加载数据,因为它是从valueStack普通select标签加载的。

您可以补充一个选择框selectBoxIcon="true"以使小部件平滑显示或在标题标签中使用相应的 jQuery 主题。试试看

<sj:autocompleter selectBox="true" selectBoxIcon="true" list="lstcountry"
    listKey="idcountry" listValue="countryname" label="Country"
    name="idcountry" /> 

来自 struts2 jQuery 插件 wiki 页面的示例。

于 2013-12-19T10:05:39.823 回答