我需要使用 Struts2-JQuery 插件实现自动完成实用程序

发布于 2024-09-24 19:04:46 字数 145 浏览 2 评论 0原文

有一个用于此目的的内置标签。

用户在文本框中输入一个字符,以输入的字符开头的字符串应显示在文本框中 列表的形式。 从列表中选择的项目应填充在文本框中。

PS:可用的示例和演示显示包含输入字符的字符串。但我只想显示那些字符串 以输入的字符开头。

There is an inbuilt tag for this purpose.

User enters a character in the textbox, Strings which start with the character entered should be displayed in the
form of a list.
The item selected from the list should be populated in the textbox.

P.S: The examples and demo available display Strings that contain the character entered. But I want only those strings to be displayed
that start with the character entered.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七分※倦醒 2024-10-01 19:04:46

插件的wiki 页面中显示了一种方法,其中它说:处理 JSON 结果的自动完成器。您只需在 jsp 中设置该代码,然后在操作中实现类似的内容:

    private static String[] staticLanguages = { ...a list... };                                                                                      
    private String term;
    private String[] languages  = Autocompleter.staticLanguages;
    public String execute() throws Exception {
            if (term != null && term.length() > 1)
            {
                    ArrayList<String> tmp = new ArrayList<String>();
                    for (int i = 0; i < staticLanguages.length; i++)
                    {
                            if (StringUtils.contains(staticLanguages[i].toLowerCase(), term.toLowerCase()))
                            {
                                    tmp.add(staticLanguages[i]);
                            }
                    }
                    languages = tmp.toArray(new String[tmp.size()]);
            }
            return SUCCESS;
    }

只需更改 StringUtils.contains 行并检查开头是否相同。

jsp 标签将是:

<sj:autocompleter 
    name="term"
    id="languages" 
    href="%{remoteurl}" 
    delay="50" 
    loadMinimumCount="2"
/>

我认为这应该可行。只需查看 wiki 中的示例代码并尝试一下即可。

A way to do that is shown in the wiki page of the pluguin where it says: Autocompleter that handle a JSON Result. Yo just set that code in your jsp, and then you implement something like this in your action:

    private static String[] staticLanguages = { ...a list... };                                                                                      
    private String term;
    private String[] languages  = Autocompleter.staticLanguages;
    public String execute() throws Exception {
            if (term != null && term.length() > 1)
            {
                    ArrayList<String> tmp = new ArrayList<String>();
                    for (int i = 0; i < staticLanguages.length; i++)
                    {
                            if (StringUtils.contains(staticLanguages[i].toLowerCase(), term.toLowerCase()))
                            {
                                    tmp.add(staticLanguages[i]);
                            }
                    }
                    languages = tmp.toArray(new String[tmp.size()]);
            }
            return SUCCESS;
    }

Just change StringUtils.contains line and check instead if the begining is the same.

The jsp tag would be:

<sj:autocompleter 
    name="term"
    id="languages" 
    href="%{remoteurl}" 
    delay="50" 
    loadMinimumCount="2"
/>

I think this should work. Just take a look at the example code in the wiki and try it out.

红尘作伴 2024-10-01 19:04:46

我使用 Struts2 和 Jquery 制作了自己的自动完成实用程序,它从 oracle 读取数据并显示建议列表,您可以根据您的要求进行相应更改。请从这里下载代码 http://javaant.com /dynamic-autocomplete-using-jquery-struts2-and-oracle/#.V0RxL5N96Hs

I made my own utility for autocomplete using Struts2 and Jquery which read the data from oracle and shows the suggestions list,you can change accordingly for your requirement. Please download the code from here http://javaant.com/dynamic-autocomplete-using-jquery-struts2-and-oracle/#.V0RxL5N96Hs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文