【问题标题】:How to load Values into the edit-form of jqGrid when user select from select box用户从选择框中选择时如何将值加载到 jqGrid 的编辑表单中
【发布时间】:2011-01-06 11:23:13
【问题描述】:


在编辑表单中是一个选择下拉菜单。当用户选择一个项目时,我想加载一些值并将它们填充到表单中。

到目前为止我的代码:

var grid = $("#list").jqGrid({
  parameters...,
  colNames:[...],
  colModel :[
    ...
  ]
});  

$("#list").jqGrid(
  'navGrid',
  '#pager',
  {
    view:true,
    edit:true,
    del:true,
    search:false,
  },

  /* EDIT */
  {
    closeAfterEdit: true,
    afterSubmit: processAddEdit,
    onInitializeForm: setFormEvents,
    ...
  }
  ...
);


function setFormEvents(formid) {
  /* It sometim works when using timeout..
   * It seems to be a timing issue.
   * But i have no idea why and how to solve
   */
  setTimeout ( function(){
    $('select#data_id', formid).unbind();
    $('select#data_id', formid).change(function() {
      $.getJSON("/URL?dataid=" + $('select#data_id option:selected').val(),
        function(data){
          $.each(data, function(i,item){
            if (item.field == "anrede") { $("#anrede").val(item.value); }
            else if (item.field == "titel") { $("#titel").val(item.value); }
            else if (item.field == "vorname") { $("#vorname").val(item.value); }
            else if (item.field == "nachname") { $("#nachname").val(item.value); }
            else if (item.field == "firma") { $("#firma").val(item.value); }
            else if (item.field == "strasse") { $("#strasse").val(item.value); }
            else if (item.field == "hausnummer") { $("#hausnummer").val(item.value); }
            else if (item.field == "plz") { $("#plz").val(item.value); }
            else if (item.field == "ort") { $("#ort").val(item.value); }
            else if (item.field == "land") { $("#land").val(item.value); }
          });
        });
    });
  }, 1000 );
}

【问题讨论】:

    标签: jquery-ui jqgrid


    【解决方案1】:

    要将事件(如您的情况下的change 事件)绑定到编辑字段,您应该使用editoptionsdataEvents。请参阅 hereherehere 示例。此外,我建议您另外使用recreateForm:true 选项。

    【讨论】:

    • 谢谢。这正是我想要的!
    猜你喜欢
    • 1970-01-01
    • 2013-07-06
    • 1970-01-01
    • 2012-03-03
    • 2021-01-07
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多