easyui datagrid 动态生成列

 for (var item_key in data) {//遍历json对象的每个key/value对,p为key
                    var reg = /^scored+/gi;
                    for (var key in data[item_key]) {//遍历json对象的每个key/value对,p为key
                        if (key === "field") {
                            if (reg.test(data[item_key][key])) {
                                data[item_key].formatter = function (value, row, index) {
                                    return "<span title='' class='easyui-tooltip icon_cus_tip_move_file'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" + value;
                                }
                            }
                            if (data[item_key][key] === "examName" || data[item_key][key] === "className") {
                                data[item_key].formatter = function (value, row, index) {
                                    return "<span title='" + value + "'  class='easyui-tooltip'>" + value + "</span>";
                                };
                            }
                            if (data[item_key][key] === "enable") {
                                data[item_key].formatter = function (value, row, index) {
                                    if (value) {
                                        return "<span class='icon_cus_checked'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>";
                                    }
                                    return "<span class='icon_cus_check'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>";
                                };
                                data[item_key].editor = {
                                    type: 'combobox',
                                    options: {
                                        panelHeight: 'auto',
                                        editable: false,
                                        data: [
                                            {
                                                value: "true",
                                                text: '出考'
                                            },
                                            {
                                                value: "false",
                                                text: '缺考'
                                            }
                                        ]
                                    }
                                };
                            }
                            if (data[item_key][key] === "remark") {
                                data[item_key].editor = {
                                    type: 'textbox',
                                    validType: 'length[0,200]'

                                }
                            }
                        }
                    }
                }
原文地址:https://www.cnblogs.com/armyant/p/9711314.html