柱与JSON 2的jQuery autocompleter [英] Struts 2 jquery autocompleter with JSON

查看:151
本文介绍了柱与JSON 2的jQuery autocompleter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的形式使用JSON atocompleter。

I'm using atocompleter in my form with json.

这是我的struts.xml中的一部分

This is the part of my struts.xml

    <package name="json" namespace="/" extends="json-default">
    <result-types>
        <result-type name="json" class="com.googlecode.jsonplugin.JSONResult" />
    </result-types>
    <action name="test" class="testClass" method="populate">
        <result type="json" name="success">
            <param name="root">itemList</param>
            <param name="contentType">text/html</param>
        </result>
    </action>
</package>

这是JSP

        <s:form id="frm_demo" name="frm_demo" theme="simple" action="test2">
         <s:url id="remoteurl" action="test" />         
        <sj:autocompleter
                            id="lst"
                            name="lst"
                            list="%{remoteurl}"
                            listValue="name"
                            listKey="id"
                            selectBox="true"
                    /> 
                     <s:submit value="submit"/>
              </s:form>

这是动作类的方法

    public String populate() throws Exception{
    itemList.put("1", "a");
    itemList.put("2", "b");
    itemList.put("3", "c");
    return "success";
}

随着struts.xml中我的jsp上面code呈现这样的 {3:C,2:B,1:1。 }

但是,当我删除的contentType参数,换句话说,内容类型是应用/ JSON的JSP弹出下载窗口。
我请将auto需要完成者返回的关键当我点击提交按钮。但是页面不与autocompleter加载。任何解决方案?
附: ITEMLIST我在动作类采用的是一个HashMap ......关系?

But when I delete the "contentType" parameter, in other words the content type is "application/json" the jsp pops the download window. I need theauto completer to return the key when i click submit button. But the page doesn't load with the autocompleter. Any solutions? p.s. itemList i used in my action class is a HashMap... does that matter?

推荐答案

使用的地图是集支持组件确定。我觉得有几个与你的code的问题。

Using map is OK with collection-backed components. I think there's couple of problems with your code.

先在你操作配置你的根对象设置为你的 ITEMLIST ,这种方式仅列表的内容将被转换成JSON,所以你不能指列表本身在autocompleter。

First in you action configuration you have set the root object to your itemList, this way only content of the list will be converted to json so you can't refer to the list itself in your autocompleter.

第二你必须设置的href 属性为您autocompleter并设置 remoteUrl ,因为它的价值。所以,你的code可能是这样的:

Second you have to set the href attribute for your autocompleter and set the remoteUrl as it's value. So your code could be like:

<package name="json" namespace="/" extends="json-default">
    <action name="test" class="testClass" method="populate">
        <result type="json"/>
    </action>
</package>

在您autompleter:

In your autompleter:

<s:form id="frm_demo" theme="simple" action="test2">
<s:url id="remoteurl" action="test" />         
<sj:autocompleter   href="%{remoteurl}"
                    id="lst"
                    name="lst"
                    list="itemList"
                    listValue="name"
                    listKey="id"
                    selectBox="true"/> 
    <s:submit value="submit"/>
</s:form>

其是否正常工作。

See if that works.

这篇关于柱与JSON 2的jQuery autocompleter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆