Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 当用户从选择框中选择时,如何将值加载到jqGrid的编辑表单中_Jquery Ui_Jqgrid - Fatal编程技术网

Jquery ui 当用户从选择框中选择时,如何将值加载到jqGrid的编辑表单中

Jquery ui 当用户从选择框中选择时,如何将值加载到jqGrid的编辑表单中,jquery-ui,jqgrid,Jquery Ui,Jqgrid,编辑表单中有一个选择下拉列表。当用户选择一个项目时,我想加载一些值并将它们填入表单中 到目前为止,我的代码是: var grid = $("#list").jqGrid({ parameters..., colNames:[...], colModel :[ ... ] }); $("#list").jqGrid( 'navGrid', '#pager', { view:true, edit:true, del:true,


编辑表单中有一个选择下拉列表。当用户选择一个项目时,我想加载一些值并将它们填入表单中

到目前为止,我的代码是:

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 );
}

要将事件(如案例中的
change
event)绑定到编辑字段,应使用的
dataEvents
。参见,或示例。此外,我建议您另外使用此选项。

谢谢。这正是我要找的!