如何在jqgrid中填充mysql的select下拉列表

s4n0splo  于 2021-09-29  发布在  Java
关注(0)|答案(0)|浏览(229)

**>你好,我是一个初学者开发人员。

选择“largecategoryzone”时,使用ASCICODE将其分隔,以从db中检索值。
我想把这些值放在“smallcategoryzone”中。下面的内容是我的代码。请检查并回答我**

$(document).ready(function () {
    $("#AdminCheckJqGrid").jqGrid({
        url: "../barcode/barcodeAdminCheckInquiry/1",
        datatype: "json",
        loadtext: "loading...",
        method: "GET",
        postData: {
            "certificateNumber": $("#certificateNumber").val()
        },
        colNames: ['sku', 'label', 'qty', 'realQty', 'palletType', 'palletBarcode','largeCategoryZone','middleCategoryZone','smallCategoryZone', 'remark'],
        colModel: [
            {label: 'sku', name: 'sku', width: '30', align: 'center'},
            {label: 'label', name: 'label', width: '60', align: 'center'},
            {label: 'qty', name: 'qty', width: '20', align: 'center'},
            {label: 'realQty', name: 'realQty', width: 30,align: 'center', sortable: false, editable: true},
            {label: 'palletType', name: 'palletType', width: 40, align: 'center', editable: true, edittype: 'select', editoptions: {dataUrl: '../code/palletType', buildSelect: setSelect}},
            {label: 'palletBarcode', name: 'palletBarcode', width: 40, align: 'center', editable: true, edittype: 'select', editoptions: {dataUrl: '../code/palletBarcode', buildSelect: palletBarcodeSelect}},
            {label: 'largeCategoryZone', name: 'largeCategoryZone', width: 40, align: 'center', editable: true, edittype: 'select', editoptions: {dataUrl: '../code/largeCategoryZone', buildSelect:setSelect ,
                    dataEvents: [{
                        type: 'change',
                        fn: function (e) {
                            var selectedData = e.currentTarget.value;
                            var dataFrist = selectedData.substr(0,1);
                            var dataAscii = dataFrist.charCodeAt();

                            $.ajax({
                                url: '../code/largeCategoryZone/' + dataAscii,
                                type: 'GET',
                                success: function (data) {
                                    var jdata = jQuery.parseJSON(data).result;
                                    var selectHtml = "";

                                    for(var i=0; i < jdata.length; i++){
                                        selectHtml += "<option value='" + jdata[i].subcode + "'>" + jdata[i].codename + "</option>";
                                    }

                                    if ($(e.target).is('.FormElement')) {
                                        var form = $(e.target).closest('form.FormGrid');
                                        console.log("form"+form);
                                        $("select#smallCategoryZone.FormElement", form[0]).html(selectHtml);
                                    } else {
                                        var row = $(e.target).closest('tr.jqgrow');
                                        var rowId = row.attr('id');
                                        var rowId = jQuery("#AdminCheckJqGrid").jqGrid('getGridParam','selrow');
                                        jQuery("select#" + rowId + "_smallCategoryZone").append(selectHtml);
                                    }
                                }
                            });
                        }}]}},
            {label: 'middleCategoryZone', name: 'middleCategoryZone', width: 40, align: 'center', editable: true, edittype: 'select', editoptions: {dataUrl: '../code/largeCategoryZone', buildSelect: setSelect}},
            {label: 'smallCategoryZone', name: 'smallCategoryZone', width: 40, align: 'center', editable: true, edittype: 'select',editoptions: {  } },
            {label: 'remark', name: 'remark', width: 50, sortable: false, editable: true, align: 'center', editoptions: {autocomplete: "off"}},
        ],
    });
});

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题