0

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

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

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

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;
        };
4

1 回答 1

0

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

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: '' });

于 2013-10-23T11:02:28.800 回答