我正在使用 JQ Grid 进行表单编辑。第二个下拉框中的数据将根据第一个下拉框的值动态填充

发布于 2024-12-07 16:38:24 字数 6098 浏览 0 评论 0原文

请帮助,我是新开发人员,我正在使用表单编辑。使用JQ Grid 的表单中有两个下拉框。第二个下拉列表中的数据将根据第一个下拉框中的值动态填充。我一直在这里阅读相关主题并尝试了这些代码,但它仍然对我不起作用。这是我的代码。 MedicineName 的值取决于用户选择的 MedicineType 的值。请帮忙,我的代码哪里出了问题?我遵循了其他人在这里发布的内容,但它仍然填充了所有药物名称列表,而不考虑第一个下拉框的值。 :( 非常感谢您的帮助。谢谢

 var MedicineType = { 'allergy': 'For Allergy / Itchiness', 'asthma': 'For Asthmatic Attacks','colds': 'For Colds / Cough', 'eye': 'For Eye Redness / Irritation','fever': 'For Fever and Pain','hyperacid': 'For Hyperacidity / Abdominal Pain' };
 var MedicineName = { '1':'Paracetamol (Tempra 250mg/mL) syrup','2':'Paracetamol (Biogesic 250mg/mL) Syrup','3':'Paracetamol (Biogesic 500mg) tab','4':'Mefenamic Acid 250mg tab','5':'Mefenamic Acid 500mg tab','6':'Neozep Non-drowsy 10mg/500mg tab','7':'Carbocistene 500mg cap','8':'Loratadine (Allerta) 5mg/5ml syrup','9':'Loratidine 10mg tab','10':'Eye mo Eye drops','11':'Isonep Eye drops','12':'Tums 500mg tab','13':'Buscopan 10mg tab','14':'Buscopan Plus 10mg/500mg tab','15':'Salbutamol Nebulization' };
 var MedicineTypecode = {
   fever: { '1': 'Paracetamol (Tempra 250mg/mL) syrup', '2': 'Paracetamol (Biogesic 250mg/mL) Syrup','3': 'Paracetamol (Biogesic 500mg) tab' ,'4': 'Mefenamic Acid 250mg tab','5': 'Mefenamic Acid 500mg tab'},
   colds: { '6': 'Neozep Non-drowsy 10mg/500mg tab', '7': 'Carbocistene 500mg cap' },
   allergy: { '8': 'Loratadine (Allerta) 5mg/5ml syrup', '9': 'Loratidine 10mg tab' },
   eye: { '10': 'Eye mo Eye drops','11': 'Eye mo Eye drops' },
   hyperacid: { '12': 'Tums 500mg tabs','13': 'Buscopan 10mg tab','14': 'Buscopan Plus 10mg/500mg tab'  }, 
   asthma: { '15': 'Salbutamol Nebulization' }};

 var lastSel = -1;
 var grid = jQuery("#ClinicAvailMed");
 var resetMedValues = function () {
    grid.setColProp('MedicineName', { editoptions: { value: MedicineTypecode } });
 };


        $("#ClinicAvailMed").jqGrid({

            datatype: "local",
            height: 100,
            width: 700,
            colNames: ['ClinicAvailmed','MEDICINE TYPE','MEDICINES'],
            colModel: [
                { name: 'ClinicAvailmed', index: 'ClinicAvailmed', sorttype: "int", editable: true, editoptions: { readonly: true, size: 2} },
                { name: 'MedTypeCode', index:'MedTypeCode', width: "50%", editable: true,  formatter: 'select', edittype: "select", editoptions: {  value: MedicineType ,dataInit: function (elem) {
                var v = $(elem).val();
                grid.setColProp('MedicineName', { editoptions: { value: MedicineTypecode [v]} });},dataEvents: [ {type: 'select', fn: function(e) {resetMedValues();
                        var v = parseInt($(e.target).val(), 10);
                        var sc = MedicineTypecode [v];
                        var newOptions = '';
                        for (var medId in sc) {
                            if (sc.hasOwnProperty(medId)) {
                                newOptions += '<option role="option" value="' +
                                              medId + '">' +
                                              med[medId] + '</option>';
                            }  }

                    if ($(e.target).is('.FormElement')) {
                            // form editing
                            var form = $(e.target).closest('form.FormGrid');
                            $("select#MedicineName.FormElement", form[0]).html(newOptions);
                        } else {
                            // inline editing
                            var row = $(e.target).closest('tr.jqgrow');
                            var rowId = row.attr('id');
                            $("select#" + rowId + "_MedicineName", row[0]).html(newOptions);
                        } } } ] }},

              { name: 'Medcode', index: 'Medcode', width: "50%", editable: true, edittype: "select", editoptions: { value: MedicineName} }, ],
         onSelectRow: function (id) {
        if (id && id !== lastSel) {
        if (lastSel != -1) {
            resetMedValues();
            grid.restoreRow(lastSel);
        }
        lastSel = id;
            } },
        ondblClickRow: function (id, ri, ci) {
            if (id && id !== lastSel) {
                grid.restoreRow(lastSel);
                lastSel = id;
            }
            resetMedValues();
            grid.editRow(id, true, null, null, 'clientArray', null,
                            function (rowid, response) {  // aftersavefunc
                                grid.setColProp('MedicineName', { editoptions: { value: MedicineTypecode } }); });
              return; },

            multiselect: false,
            caption: " ",
            editurl: "handlers/store.ashx?table=ClinicAvailMed",
            ondblClickRow: function(id) { { $("#ClinicAvailMed").editGridRow(id, { modal: true, drag: true, addCaption: "Add Medicine", editCaption: "Edit Medicine", bSubmit: "OK", bCancel: "Close", closeAfterEdit: true }); } }

        });
        $("#ClinicAvailMed").jqGrid('hideCol', 'ClinicAvailmed');
        $("#btnAddClinicAmed").click(function() { $("#ClinicAvailMed").editGridRow('new', { modal: true, drag: true, addCaption: "Add Medicine", editCaption: "Edit Medicine", bSubmit: "OK", bCancel: "Close", closeAfterEdit: true, addedrow: 'last' }); });
        $("#btnEditClinicAmed").click(function() {
        var _selectedRow = $("#ClinicAvailMed").getGridParam('selrow');
        if (_selectedRow != null) { $("#ClinicAvailMed").editGridRow(_selectedRow, { modal: true, drag: true, addCaption: "Add Medicine", editCaption: "Edit Medicine", bSubmit: "OK", bCancel: "Close", closeAfterEdit: true }); }
            else { alert("Please select the row which you want to edit."); }});
        $("#btnDeleteClinicAmed").click(function() {
        var _selectedRow = $("#ClinicAvailMed").getGridParam('selrow');
        if (_selectedRow != null) { $("#ClinicAvailMed").delGridRow(_selectedRow, { drag: true, msg: "Delete the row(s)?", caption: "Delete", bSubmit: "Yes", bCancel: "Close", modal: true }); }
        else { alert("Please select the row which you want to edit."); } });

Please help, I am a new developer and I am using form edit. There are two drop down boxes in the form using JQ Grid. The data on the second drop down will be populated dynamically based on the value on first drop box. I had been reading related topics here and tried those codes but still it didn't worked for me. Here are my codes. The value of the MedicineName depends on what is the value of the MedicineType choose by the user. Please help, where did I went wrong with my codes? I followed what is posted by others here but still it populate all the lists of medicine names without considering the value of the first drop box. :( You're help is highly appreciated. Thanks

 var MedicineType = { 'allergy': 'For Allergy / Itchiness', 'asthma': 'For Asthmatic Attacks','colds': 'For Colds / Cough', 'eye': 'For Eye Redness / Irritation','fever': 'For Fever and Pain','hyperacid': 'For Hyperacidity / Abdominal Pain' };
 var MedicineName = { '1':'Paracetamol (Tempra 250mg/mL) syrup','2':'Paracetamol (Biogesic 250mg/mL) Syrup','3':'Paracetamol (Biogesic 500mg) tab','4':'Mefenamic Acid 250mg tab','5':'Mefenamic Acid 500mg tab','6':'Neozep Non-drowsy 10mg/500mg tab','7':'Carbocistene 500mg cap','8':'Loratadine (Allerta) 5mg/5ml syrup','9':'Loratidine 10mg tab','10':'Eye mo Eye drops','11':'Isonep Eye drops','12':'Tums 500mg tab','13':'Buscopan 10mg tab','14':'Buscopan Plus 10mg/500mg tab','15':'Salbutamol Nebulization' };
 var MedicineTypecode = {
   fever: { '1': 'Paracetamol (Tempra 250mg/mL) syrup', '2': 'Paracetamol (Biogesic 250mg/mL) Syrup','3': 'Paracetamol (Biogesic 500mg) tab' ,'4': 'Mefenamic Acid 250mg tab','5': 'Mefenamic Acid 500mg tab'},
   colds: { '6': 'Neozep Non-drowsy 10mg/500mg tab', '7': 'Carbocistene 500mg cap' },
   allergy: { '8': 'Loratadine (Allerta) 5mg/5ml syrup', '9': 'Loratidine 10mg tab' },
   eye: { '10': 'Eye mo Eye drops','11': 'Eye mo Eye drops' },
   hyperacid: { '12': 'Tums 500mg tabs','13': 'Buscopan 10mg tab','14': 'Buscopan Plus 10mg/500mg tab'  }, 
   asthma: { '15': 'Salbutamol Nebulization' }};

 var lastSel = -1;
 var grid = jQuery("#ClinicAvailMed");
 var resetMedValues = function () {
    grid.setColProp('MedicineName', { editoptions: { value: MedicineTypecode } });
 };


        $("#ClinicAvailMed").jqGrid({

            datatype: "local",
            height: 100,
            width: 700,
            colNames: ['ClinicAvailmed','MEDICINE TYPE','MEDICINES'],
            colModel: [
                { name: 'ClinicAvailmed', index: 'ClinicAvailmed', sorttype: "int", editable: true, editoptions: { readonly: true, size: 2} },
                { name: 'MedTypeCode', index:'MedTypeCode', width: "50%", editable: true,  formatter: 'select', edittype: "select", editoptions: {  value: MedicineType ,dataInit: function (elem) {
                var v = $(elem).val();
                grid.setColProp('MedicineName', { editoptions: { value: MedicineTypecode [v]} });},dataEvents: [ {type: 'select', fn: function(e) {resetMedValues();
                        var v = parseInt($(e.target).val(), 10);
                        var sc = MedicineTypecode [v];
                        var newOptions = '';
                        for (var medId in sc) {
                            if (sc.hasOwnProperty(medId)) {
                                newOptions += '<option role="option" value="' +
                                              medId + '">' +
                                              med[medId] + '</option>';
                            }  }

                    if ($(e.target).is('.FormElement')) {
                            // form editing
                            var form = $(e.target).closest('form.FormGrid');
                            $("select#MedicineName.FormElement", form[0]).html(newOptions);
                        } else {
                            // inline editing
                            var row = $(e.target).closest('tr.jqgrow');
                            var rowId = row.attr('id');
                            $("select#" + rowId + "_MedicineName", row[0]).html(newOptions);
                        } } } ] }},

              { name: 'Medcode', index: 'Medcode', width: "50%", editable: true, edittype: "select", editoptions: { value: MedicineName} }, ],
         onSelectRow: function (id) {
        if (id && id !== lastSel) {
        if (lastSel != -1) {
            resetMedValues();
            grid.restoreRow(lastSel);
        }
        lastSel = id;
            } },
        ondblClickRow: function (id, ri, ci) {
            if (id && id !== lastSel) {
                grid.restoreRow(lastSel);
                lastSel = id;
            }
            resetMedValues();
            grid.editRow(id, true, null, null, 'clientArray', null,
                            function (rowid, response) {  // aftersavefunc
                                grid.setColProp('MedicineName', { editoptions: { value: MedicineTypecode } }); });
              return; },

            multiselect: false,
            caption: " ",
            editurl: "handlers/store.ashx?table=ClinicAvailMed",
            ondblClickRow: function(id) { { $("#ClinicAvailMed").editGridRow(id, { modal: true, drag: true, addCaption: "Add Medicine", editCaption: "Edit Medicine", bSubmit: "OK", bCancel: "Close", closeAfterEdit: true }); } }

        });
        $("#ClinicAvailMed").jqGrid('hideCol', 'ClinicAvailmed');
        $("#btnAddClinicAmed").click(function() { $("#ClinicAvailMed").editGridRow('new', { modal: true, drag: true, addCaption: "Add Medicine", editCaption: "Edit Medicine", bSubmit: "OK", bCancel: "Close", closeAfterEdit: true, addedrow: 'last' }); });
        $("#btnEditClinicAmed").click(function() {
        var _selectedRow = $("#ClinicAvailMed").getGridParam('selrow');
        if (_selectedRow != null) { $("#ClinicAvailMed").editGridRow(_selectedRow, { modal: true, drag: true, addCaption: "Add Medicine", editCaption: "Edit Medicine", bSubmit: "OK", bCancel: "Close", closeAfterEdit: true }); }
            else { alert("Please select the row which you want to edit."); }});
        $("#btnDeleteClinicAmed").click(function() {
        var _selectedRow = $("#ClinicAvailMed").getGridParam('selrow');
        if (_selectedRow != null) { $("#ClinicAvailMed").delGridRow(_selectedRow, { drag: true, msg: "Delete the row(s)?", caption: "Delete", bSubmit: "Yes", bCancel: "Close", modal: true }); }
        else { alert("Please select the row which you want to edit."); } });

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蹲墙角沉默 2024-12-14 16:38:24

查看演示:this 来自 旧答案另一个。这些演示展示了如何在表单编辑中实现依赖选择、 内联编辑工具栏搜索

Look at the demos: this and this from the old answer and another one. The demos show how one can implement dependent selects in form editing, inline editing and in the toolbar search.

新雨望断虹 2024-12-14 16:38:24

resetMedValues 中,您使用 grid.setColProp('MedicineName'... ,尽管您没有任何具有该名称的列。这绝对是错误的。

In resetMedValues you use grid.setColProp('MedicineName'... althought you do not have any column with that name. This is definitely a false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文