首页 > 解决方案 > 在easyui可编辑数据网格中动态添加选择框选项

问题描述

我正在使用 easyui 可编辑数据网格,我必须在其中显示带有一些选项的选择下拉列表。我在下面尝试过:

<table id="bulkchannel_edit" style="width:100%; height:500px;"></table>

javascript:

var parentCategories = {};
$(document).ready(function(){
     $.ajax({
           url: "<?php echo base_url() ?>index.php/Channels/getParentChildChannelCategories",
           dataType: 'json',
           success: function(response){
               console.log('response',response);
               console.log('parent_categories',response.parent_categories);
               parentCategories = response.parent_categories;
               // childCategories = response.child_categories;
           }
     });
 });

$(function(){
   $('#bulkchannel_edit').datagrid({
    title:'Editable DataGrid',
    iconCls:'icon-edit',
    singleSelect:true,
    idField:'itemid',
    url:'<?php echo base_url() ?>index.php/Channels/get_test_json_data',
    columns:[[
       {field:'channel_name',title:'Channel Name',editor:"textbox"},
       {field:'category_name',title:'Category',width:100,
            editor:{
                 type:'combobox',
                 options:{
                  valueField:'channel_category_id',
                  textField:'category_name',
                  data:parentCategories,
                  required:true
                 }
             }
        }
     ]]
   });
 });

在上面的代码中,我想为“category_name”加载一个选择下拉选项,在其中我从 ajax 调用“Channels/getParentChildChannelCategories”动态获取 json 数据,如下所示:

点击这里

显示为空下拉列表,没有其他选项,只有一个主值,必须与选择框中的所有选项一起显示为选定选项。如下图所示:

在此处输入图像描述

任何帮助,谢谢。

标签: javascriptjqueryjsondatagridjquery-easyui

解决方案


推荐阅读