Я не могу добавить новую запись в EditorGridPanel - PullRequest
0 голосов
/ 13 ноября 2011

В настоящее время я преподаю EditorGridPanel в Ext JS 3.1.0.Мне удалось создать сетку, которая показывает список городов.Однако у меня возникает проблема, когда я пытаюсь добавить новую запись в базу данных.Когда я нажимаю кнопку «Добавить город», ничего не происходит, и Firebug выдает ошибку:

Uncaught ReferenceError: newCity is not defined
Ext.grid.EditorGridPanel.tbar.handlereg02.html: 96
Ext.Button.Ext.extend.onClickext-all-debug.js: 27083
h

Это мой код:

Ext.onReady(function(){

//===== Data Store ================================================== (2)
var store = new Ext.data.Store({
                url: 'city_for_eg01.php',
                reader: new Ext.data.JsonReader({
                root:'rows',
                id:'zip'
            }, [
                'zip',
                'city'
            ]),
            api: {
                    create : 'city_for_eg01.php?action=create',
                    read : 'city_for_eg01.php?action=read',
                    update: 'city_for_eg01.php?action=update',
                    destroy: 'city_for_eg01.php?action=destroy'
                },
            writer: new Ext.data.JsonWriter({
                 writeAllFields: true
                }),
            autoSave: false,
        });
store.load();
//=================================================================== end (2)

var editor = new Ext.form.TextField();

var grid = new Ext.grid.EditorGridPanel({
        renderTo: document.body,
        frame:true,
        title: 'City',
        height:200,
        width:520,
        clickstoEdit: 1,
        store: store,
        columns: [
                    {header: "ZIP", dataIndex: 'zip', editor: editor},
                    {header: "CITY", dataIndex: 'city', editor: editor},
                  ],
        listeners: {
                    afteredit: function(e){e.record.commit();}
      },
        tbar: [{
            text: 'Add City',
            icon: 'images/table_add.png',
            cls: 'x-btn-text-icon',
            handler: function() {
                        Ext.Ajax.request({
                                url: 'city-update.php',
                                params: {
                                            action: 'create',
                                            zip: 'zip'
                                         },
                                success: function(resp,opt) {
                                            grid.getStore().insert(0,
                                            new newCity{
                                                    zip: 'New Zip',
                                                    city: 'New City'    
                                                  })
                                         );
                                            grid.startEditing(0,0);
                             },
                                failure: function(resp,opt) {   
                                                    Ext.Msg.alert('Error','Unable to add city');
                                                  }
                    });
                }
         }]               
    });
});

1 Ответ

1 голос
/ 13 ноября 2011

Это потому, что не определена newCity функция.

Вы должны быть в состоянии заставить его работать с:

new store.recordType(/* values */)

recordType содержит конструктор для нового Record для этого магазина.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...