0

我有两个下拉列表,第一个从数据库值中填充,第二个(PriceCode)取决于用户在第一个(CurrCd)中选择的内容。我的问题是如何动态填充第二个列表?我正在尝试这样做,dataEvents但无法在编辑模式下引用第二个下拉列表。有没有正确和合乎逻辑的方法?

到目前为止,这是我的代码:

 grid.jqGrid({
            datatype: 'local',
            jsonReader: als.common.jqgrid.jsonReader('EntityCd'),
            mtype: 'POST',
            pager: '#billingPager',
            loadonce: true,
            colNames: ['Currency', 'Status', 'Bill Curr', 'Price Code'],
            colModel: [
                {
                               { name: 'DefaultCurr', index: 'DefaultCurr', width: 20, sortable: false },
                { name: 'BillStatus', index: 'BillStatus', width: 13, sortable: false },
                {
                    name: 'CurrCd', index: 'CurrCd', width: 20, sortable: false,
                    editable: true,
                    edittype: 'select', stype: 'select',
                    editoptions: {
                        dataUrl: als.common.getServerPath() + 'LegalEntitiesAjax/GetCurrencies',
                        dataEvents:[{
                            type:"change",
                            fn: function (e) {

                                //populate price code list here                           
                                //below does not work to populate PriceCode

                                $.ajax({
                                    type: 'POST',
                                    traditional: true,
                                    contentType: 'application/json; charset=utf-8',
                                    url: als.common.getServerPath() + 'LegalEntitiesAjax/GetPriceList',
                                    data: JSON.stringify({ curcd: this.value }),
                                    async: false,
                                    success: function (data) {                                       

                                        for(i=0; i < data.length; i++) {
                                            $('select#PriceCode').append('<option val=\"' + data[i].PriceCode + '">' + data[i].Description + '</option>');
                                        }


                                    },
                                    error: function (val) { }
                                });


                            }
                        }],

                        buildSelect: function (data) {
                            var currSelector = $("<select id='selCurr' />");
                            $(currSelector).append($("<option/>").val('').text('---Select Currency---'));
                            var currs = JSON.parse(data);
                            $.each(currs, function () {
                                var text = this.CurName;
                                var value = this.CurCode;
                                $(currSelector).append($("<option />").val(value).text(text));
                            });

                            return currSelector;
                        }
                    }
                },
                { name: 'PriceCode', index: 'PriceCode', width: 20, sortable: false, editable: true, edittype: 'select', stype: 'select'}
            ],
            loadtext: 'Loading...',
            caption: "Bill Entities",
            scroll: true,
            hidegrid: false,
            height: 300,
            width: 650,
            rowNum: 1000,
            altRows: true,
            altclass: 'gridAltRowClass',
            onSelectRow: webview.legalentities.billing.onBillingSelected,
            loadComplete: function (data) {
                if (data.length > 0)
                {

                }
                var rowIds = $('#billingGrid').jqGrid('getDataIDs');
                $("#billingGrid").jqGrid('setSelection', rowIds[0]);
            },
            rowNum: 1000
        });
        grid.jqGrid('navGrid', '#billingPager', {
            add: ($("#dev").text() == "True" || $("#globalqc").text() == "True"),
            edit: false,
            del: false,
            search: false,
            refresh: false
        },
        { // Edit Options  
        },
        { // Add Options
            addCaption: 'Add New Billing Entity',
            beforeInitData: function (formid) {

            },
            url: als.common.getServerPath() + 'LegalEntitiesAjax/AddBillingEntity/',
            recreateForm: true,
            closeAfterAdd: true,
            reloadAfterSubmit: true
        },
        { // Del Options
        });
4

1 回答 1

0

旧答案显示了如何实现依赖选择。您使用表单编辑。因此,表单编辑的列<select>元素将具有 id="PriceCode"。PriceCode您可以使用$("#PriceCode").html(/*new options*/);更改列的事件处理程序内的列的<select>编辑字段的选项。PriceCodechangeCurrCd

于 2016-06-08T10:48:35.853 回答