easyui datagrid combobox下拉框获取数据问题

最近在使用easyui的datagrid,在可编辑表格中添加一个下拉框,查了下API,可以设置type : 'combobox',来做下拉框,这下拉框是有了,可是这后台数据怎么传过来呢,通过查API可以知道,设置URL属性就能从一个URL远程站点请求数据,或者设置data属性也行,但是本人两种方式都试了,这个数据就是现实不出来,原来是因为data这里需要放一个json格式的数据才行,我之前放的也是json,但是其中又嵌套了好几层,最后重新修改,OK啦!记录

  1.   
  1.   
  1. $.ajax({    
  2.         url:'packagetype.do',    
  3.         dataType : 'json',    
  4.         type : 'POST',    
  5.         async:false,  
  6.         success: function (data){    
  7.         <span style="white-space:pre">  </span>packageTypeList = data;  
  8.         }    
  9.   });  
  1. $('#businessVersion').datagrid(  
  2.                     {  
  3.                         url : "VersionList.do?id="  
  4.                                 + $("#bId").val(),  
  5.                         idField : 'id',  
  6.                         pageSize : '10',  
  7.                         pageNumber : '1',  
  8.                         pageList : [ 5, 10 ],  
  9.                         columns : [ [  
  10.                                 {  
  11.                                     field : 'id',  
  12.                                     checkbox : true  
  13.                                 },  
  14.                                 {  
  15.                                     field : 'fileName',  
  16.                                     title : '安裝包名称',  
  17.                                     width : 320,  
  18.                                     align : 'center',  
  19.                                     editor : {  
  20.                                         type : 'text',  
  21.                                         required: true  
  22.                                     }  
  23.                                 },  
  24.                                 {  
  25.                                     field : 'versionNo',  
  26.                                     title : '版本号',  
  27.                                     width : 220,  
  28.                                     align : 'center',  
  29.                                     editor : {  
  30.                                         type : 'text',  
  31.                                         required: true   
  32.                                     }  
  33.                                 },  
  34.                                 {  
  35.                                     field : 'packageType',  
  36.                                     title : '安装包类型',  
  37.                                     width : 220,  
  38.                                     align : 'center',  
  39.                                     formatter: function(value,row,index) {    
  40.                                         return row['packageName'];  
  41.                                     },  
  42.                                     editor : {  
  43.                                         type : 'combobox',  
  44.                                         options : {  
  45.                                         data: packageTypeList,  
  46. //                                      url:'packagetype.do',  
  47.                                         valueField: 'id',    
  48.                                             textField: 'name',    
  49.                                             panelHeight: 'auto',  
  50.                                             required: true ,  
  51.                                             editable:false  
  52.                                         }  
  53.                                     }  
  54.                                 },  
  55.                                 {  
  56.                                     field : 'operation',  
  57.                                     title : '操作',  
  58.                                     width : 320,  
  59.                                     align : 'center',  
  60.                                     formatter : function(value, row, index) {  
  61.                                         var links = "";  
  62.                                         if (row['fileName'] == '') {  
  63.                                             links = links + "  ";  
  64.                                             links = links  
  65.                                                     + "<a href="javascript:void(0);" "  
  66.                                                     + "onclick="fileUpload("  
  67.                                                     + index + ");" >上传文件</a>";  
  68.                                             links = links + "  ";  
  69.                                             links = links  
  70.                                                     + "<input type='text' id='packUrl"  
  71.                                                     + index  
  72.                                                     + "' style='display:none;'/>";  
  73.                                         } else {  
  74.                                             links = links + "  ";  
  75.                                             links = links  
  76.                                                     + "<a href="javascript:void(0);"  "  
  77.                                                     + "onclick="fileDownload('"  
  78.                                                     + row['packageAdress']  
  79.                                                     + "');" >下载文件</a>";  
  80.                                             links = links + "  ";  
  81.                                         }  
  82.                                         return links;  
  83.                                     }  
  84.                                 } ] ],  
  85.                         toolbar : [  
  86.                                 {  
  87.                                     id : "businessAdd",  
  88.                                     text : '新增',  
  89.                                     iconCls : 'icon-add',  
  90.                                     handler : function() {  
  91.                                         $('#businessVersion').datagrid(  
  92.                                                 'endEdit', lastIndex);  
  93.                                         $('#businessVersion').datagrid(  
  94.                                                 'appendRow', {  
  95.                                                     fileName : '',  
  96.                                                     versionNo : '',  
  97.                                                     creator : '',  
  98.                                                     packageType : '',  
  99.                                                     operation : ''  
  100.                                                 });  
  101.                                         var lastIndex = $('#businessVersion')  
  102.                                                 .datagrid('getRows').length - 1;  
  103.                                         $('#businessVersion').datagrid(  
  104.                                                 'selectRow', lastIndex);  
  105.                                         $('#businessVersion').datagrid(  
  106.                                                 'beginEdit', lastIndex);  
  107.                                     }  
  108.                                 },  
  109.                                 {  
  110.                                     id : "bDestory",  
  111.                                     text : '撤消',  
  112.                                     iconCls : 'icon-undo',  
  113.                                     handler : function() {  
  114.                                         $('#businessVersion').datagrid(  
  115.                                                 'rejectChanges');  
  116.                                     }  
  117.                                 } ]  
  118.                     });  
原文地址:https://www.cnblogs.com/sjqq/p/7413366.html