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

时间:2013-10-21 15:36:56

标签: javascript jquery html5 extjs4

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

请注意,根据单选按钮检查编辑是否发生。

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

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

1 个答案:

答案 0 :(得分:0)

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

var record = new Sch.model.Resource({   //在这里,这需要独特// Id:0,                 来源:焦点市场? focusmarket.Origin:'',                 目的地:焦点市场? focusmarket.Destination:'',                 CabinClass:焦点市场? focusmarket.CabinClass:'',                 StartAvailability:focusmarket? focusmarket.startAvailability:'',                 EndAvailability:focusmarket? focusmarket.endAvailability:''                 });