jqgrid:如何在表单编辑中更新下拉列表的dataurl

时间:2013-09-18 03:16:06

标签: jquery jqgrid

我想实现一个依赖的下拉列表(例如,A取决于B)。在进行表单编辑时,对话框显示的时间,B无法知道A的选定值,因此B无法更新其dataurl。

任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

你有没有得到任何东西..如果不是我有同样的问题并解决了。可能对你没有用,但对其他人有用。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

<script>


    grid.jqGrid({
        data: mydata,
        datatype: 'local',
      ondblClickRow: function(rowid) {
        jQuery(this).jqGrid('editGridRow', rowid,
                            {recreateForm:true,closeAfterEdit:true,
                               closeOnEscape:true,reloadAfterSubmit:false});
       },
        colModel: [
            { name: 'Name', w 200 },
            { name: 'Country', width: 100, editable: true, formatter: 'select',
                edittype: 'select', editoptions: {
                    value: <someStaticOrDynamicValues>,                     
                    },
                    dataEvents: [
                        {
                            type: 'change',
                            fn: function(e) {
                                changeStateSelect(e);
                            }
                        }
                    ]
                }
            },
            {
                name: 'State', width: 100, editable: true, formatter: 'select',
                edittype: 'select', editoptions: { value: states }
            }
        ],      

    });

    function changeStateSelect(e){
            var countryId = $(e.target).val();
            $.ajax({
                url:"getStateList.html?countryId="+countryId,
                type: "post",
                success:function(newOptions){
                    var form = $(e.target).closest("form.FormGrid");
                    $("select#State.FormElement",form[0]).html(newOptions);
                }
            });
        }
</script>
 <BODY>

 </BODY>
</HTML>

JAVA中的某些地方

   @RequestMapping(value = "/getStateList.html", method = RequestMethod.POST)
    public @ResponseBody String getSuperVisorList(@RequestParam("countryId") String countryId) throws Exception {

        StringBuffer select = new StringBuffer("<select>");
        select.append("<option value=''>  </option>");
        for (int i =0; i<10; i++) {
            select.append("<option value='" 
                        + i
                        + "'>" + "youValues" + "</option>");
        }
        select.append("</select>");
        return select.toString();
    }