最近在使用easyui的datagrid,在可编辑表格中添加一个下拉框,查了下API,可以设置type : 'combobox',来做下拉框,这下拉框是有了,可是这后台数据怎么传过来呢,通过查API可以知道,设置URL属性就能从一个URL远程站点请求数据,或者设置data属性也行,但是本人两种方式都试了,这个数据就是现实不出来,原来是因为data这里需要放一个json格式的数据才行,我之前放的也是json,但是其中又嵌套了好几层,最后重新修改,OK啦!记录
- $.ajax({
- url:'packagetype.do',
- dataType : 'json',
- type : 'POST',
- async:false,
- success: function (data){
- <span style="white-space:pre"> </span>packageTypeList = data;
- }
- });
- $('#businessVersion').datagrid(
- {
- url : "VersionList.do?id="
- + $("#bId").val(),
- idField : 'id',
- pageSize : '10',
- pageNumber : '1',
- pageList : [ 5, 10 ],
- columns : [ [
- {
- field : 'id',
- checkbox : true
- },
- {
- field : 'fileName',
- title : '安裝包名称',
- width : 320,
- align : 'center',
- editor : {
- type : 'text',
- required: true
- }
- },
- {
- field : 'versionNo',
- title : '版本号',
- width : 220,
- align : 'center',
- editor : {
- type : 'text',
- required: true
- }
- },
- {
- field : 'packageType',
- title : '安装包类型',
- width : 220,
- align : 'center',
- formatter: function(value,row,index) {
- return row['packageName'];
- },
- editor : {
- type : 'combobox',
- options : {
- data: packageTypeList,
- // url:'packagetype.do',
- valueField: 'id',
- textField: 'name',
- panelHeight: 'auto',
- required: true ,
- editable:false
- }
- }
- },
- {
- field : 'operation',
- title : '操作',
- width : 320,
- align : 'center',
- formatter : function(value, row, index) {
- var links = "";
- if (row['fileName'] == '') {
- links = links + " ";
- links = links
- + "<a href=\"javascript:void(0);\" "
- + "onclick=\"fileUpload("
- + index + ");\" >上传文件</a>";
- links = links + " ";
- links = links
- + "<input type='text' id='packUrl"
- + index
- + "' style='display:none;'/>";
- } else {
- links = links + " ";
- links = links
- + "<a href=\"javascript:void(0);\" "
- + "onclick=\"fileDownload('"
- + row['packageAdress']
- + "');\" >下载文件</a>";
- links = links + " ";
- }
- return links;
- }
- } ] ],
- toolbar : [
- {
- id : "businessAdd",
- text : '新增',
- iconCls : 'icon-add',
- handler : function() {
- $('#businessVersion').datagrid(
- 'endEdit', lastIndex);
- $('#businessVersion').datagrid(
- 'appendRow', {
- fileName : '',
- versionNo : '',
- creator : '',
- packageType : '',
- operation : ''
- });
- var lastIndex = $('#businessVersion')
- .datagrid('getRows').length - 1;
- $('#businessVersion').datagrid(
- 'selectRow', lastIndex);
- $('#businessVersion').datagrid(
- 'beginEdit', lastIndex);
- }
- },
- {
- id : "bDestory",
- text : '撤消',
- iconCls : 'icon-undo',
- handler : function() {
- $('#businessVersion').datagrid(
- 'rejectChanges');
- }
- } ]
- });