单击添加按钮时需要在网格中添加多个记录

Need to add the multiple records in grid when I click the add button?

本文关键字:添加 记录 网格 按钮 单击      更新时间:2023-09-26

当我单击按钮时,我必须将多个记录添加到网格中。但它每次只添加一条记录。也就是说,它添加一个记录;之后,它只能添加记录。

请注意,基于单选按钮检查编辑发生。

如果错误,任何人都可以纠正代码吗?

tbar: [
                {
                    text: 'Add',
                    tooltip: 'Add Focus Market',
                    iconCls: 'icon-shift-add',
                    scope: me,
                    handler: function() {
                            addFocusMarket.call(this);
                    }
                }
            ],
plugins: [ this.mcmRowEditing ],
            viewConfig: {},
            listeners: {
                scope: me,
                validateedit: function(editor, e) {
                    var searchval = Ext.getCmp('searchGroup').getValue();
                    if(searchval.search_type == "CityPair" ) {
                        console.log("city pair update..");
                        if(e.newValues.Origin !== e.originalValues.Origin ||
                            e.newValues.Destination !== e.originalValues.Destination ||
                            e.newValues.CabinClass !== e.originalValues.CabinClass ||
                            e.newValues.StartAvailability.getDate() !== e.originalValues.StartAvailability.getDate() ||
                            e.newValues.EndAvailability.getDate() !== e.originalValues.EndAvailability.getDate()) {

                            if(!e.newValues.Origin) {
                                App.mcmShowMessageBox({
                                title: 'Important', 
                                message: 'Please set the Origin', 
                                time: 2000
                            });
                            return false; }
                            if(!e.newValues.Destination) {
                                App.mcmShowMessageBox({
                                title: 'Important', 
                                message: 'Please set the Destination', 
                                time: 2000
                            });
                            return false; }
                            if(!e.newValues.CabinClass) {
                                App.mcmShowMessageBox({
                                title: 'Important', 
                                message: 'Please enter a valid CabinClass', 
                                time: 2000
                            });
                            return false; }
                            e.newValues.Origin = e.newValues.Origin.toUpperCase();
                            e.newValues.Destination = e.newValues.Destination.toUpperCase();
                            e.record.set('Origin', e.newValues.Origin);
                            e.record.set('Destination', e.newValues.Destination);
                            e.record.set('CabinClass', e.newValues.CabinClass);
                            e.record.set('StartAvailability', e.newValues.StartAvailability);
                            e.record.set('EndAvailability', e.newValues.EndAvailability);
                            App.mcmAddCityPair({
                                focusmarketRecord: e.record, 
                                successCallback: function(obj) {
                                    e.record.data = obj;
                                    App.mcmFindCityPair(this.mcmSearchType, obj.Origin, obj.Destination, 
                                        obj.StartAvailability, obj.EndAvailability);
                                    this.mcmHasChanges = true;
                                }, 
                                successScope: this,
                                failureCallback: App.mcmTabReload,
                                failureScope: App
                            });
                      }
                    }
                    else if(searchval.search_type == "IndividualFlights") {
                        console.log("flight number update..");
                        if(e.newValues.Origin !== e.originalValues.Origin ||
                            e.newValues.Destination !== e.originalValues.Destination ||
                            e.newValues.CabinClass !== e.originalValues.CabinClass ||
                            e.newValues.FlightNumber !== e.originalValues.FlightNumber ||
                            e.newValues.StartAvailability.getDate() !== e.originalValues.StartAvailability.getDate() ||
                            e.newValues.EndAvailability.getDate() !== e.originalValues.EndAvailability.getDate()) {
                            if(!e.newValues.FlightNumber) {
                                App.mcmShowMessageBox({
                                title: 'Important', 
                                message: 'Please enter a valid FlightNumber', 
                                time: 2000
                            });
                            return false; }

                            if(!e.newValues.Origin) {
                                App.mcmShowMessageBox({
                                title: 'Important', 
                                message: 'Please set the Origin', 
                                time: 2000
                            });
                            return false; }
                            if(!e.newValues.Destination) {
                                App.mcmShowMessageBox({
                                title: 'Important', 
                                message: 'Please set the Destination', 
                                time: 2000
                            });
                            return false; }
                            if(!e.newValues.CabinClass) {
                                App.mcmShowMessageBox({
                                title: 'Important', 
                                message: 'Please enter a valid CabinClass', 
                                time: 2000
                            });
                            return false; }
                            e.newValues.Origin = e.newValues.Origin.toUpperCase();
                            e.newValues.Destination = e.newValues.Destination.toUpperCase();
                            e.record.set('Origin', e.newValues.Origin);
                            e.record.set('Destination', e.newValues.Destination);
                            e.record.set('CabinClass', e.newValues.CabinClass);
                            e.record.set('FlightNumber', e.newValues.FlightNumber);
                            e.record.set('StartAvailability', e.newValues.StartAvailability);
                            e.record.set('EndAvailability', e.newValues.EndAvailability);
                            App.mcmAddIndividaulFlight({
                                focusmarketRecord: e.record, 
                                successCallback: function(obj) {
                                    e.record.data = obj;
                                    App.mcmFindIndividualFlights(this.mcmSearchType, obj.Origin, obj.Destination, 
                                            obj.StartAvailability, obj.EndAvailability, obj.FlightNumber);
                                    this.mcmHasChanges = true;
                                }, 
                                successScope: this,
                                failureCallback: App.mcmTabReload,
                                failureScope: App
                            });
                        }
                    }
                }
            }


    var addFocusMarket = function(focusmarket) {
            this.mcmRowEditing.cancelEdit();
            var searchval = Ext.getCmp('searchGroup').getValue();
            console.log("add focus market" + focusmarket);
            if(searchval.search_type == "CityPair"){
                var record = new Sch.model.Resource({
                Id: 0, 
                Origin: focusmarket ? focusmarket.Origin : '',
                Destination: focusmarket ? focusmarket.Destination: '',
                CabinClass: focusmarket ? focusmarket.CabinClass: '',
                StartAvailability: focusmarket ? focusmarket.startAvailability: '', 
                EndAvailability: focusmarket ? focusmarket.endAvailability: ''
                });
                console.log("records-->"+record);
            }
            else if(searchval.search_type == "IndividualFlights"){
                var record = new Sch.model.Resource({
                Id: 0, 
                Origin: focusmarket ? focusmarket.Origin : '',
                Destination: focusmarket ? focusmarket.Destination: '',
                FlightNumber: focusmarket ? focusmarket.FlightNumber: '',
                CabinClass: focusmarket ? focusmarket.CabinClass: '',
                StartAvailability: focusmarket ? focusmarket.startAvailability: '', 
                EndAvailability: focusmarket ? focusmarket.endAvailability: ''
                });
                console.log("records-->"+record);
            }
            App.mcmFocusMarketStore.insert(0, record);
            this.mcmRowEditing.startEdit(0, 0);
            this.mcmHasChanges = true;
        };

当您创建ID时,请尝试使用唯一的ID。如果每次创建记录时都输入 0 作为 id,则网格中只会看到一条记录。每次使用 Ext.id() 或编写自己的 id 时,都需要生成一个唯一的 id。

var record = new Sch.model.Resource({//就在这里,这必须是唯一的//Id:0, 产地:焦点市场?焦点市场。原产地 : '', 目的地: 焦点市场 ?焦点市场。目的地: '', 舱位等级:焦点市场 ?焦点市场。舱位等级: ", 开始可用性: 焦点市场 ?focusmarket.startAvailability: '', 终端可用性: 焦点市场 ?focusmarket.endAvailability: '' });