保存记录时,重新加载存储和刷新网格不起作用。 Extjs

时间:2019-07-19 08:07:50

标签: javascript extjs

我的应用程序由Ext.grid.Panel组成以显示记录列表,由Ext.window.Window组成以编辑和添加记录。 保存记录时,saveRecord方法可在ViewController中工作

Ext.define('App.view.operation.OperationViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.operation_controller', 
    saveRecord: function (button) {     
        var wind = button.up('window'),form = button.up('form');
        var storeOperat = wind.getViewModel().get('Operations');
        var gridOperat = Ext.ComponentQuery.query('operation-grid')[0];
        var record = form.getRecord(), values = form.getValues();       
       if (form.isValid()) { 
            //add record
            if(Ext.Object.isEmpty(record)){                             
                model = gridOperat.getView().getStore().insert(0, values);
                storeOperat.add(model);         
                storeOperat.sync();
                storeOperat.reload();//does not work!
                gridOperat.getView().refresh();//does not work!    
                wind.close();
            }//update record
            else{                        
                id = form.getRecord().get('id');                
                values.id=id;               
                record.set(values); 
                record.store.sync();
                record.store.reload(); 
                gridOperat.getView().refresh();      
                wind.close();                                           
            }           
       }
       else{
            Ext.Msg.alert('Status', 'Error filling the form.');
       }

    },
    ....

网格模型如下:

var urlRoot = 'app/data/crud.php?model=Operation&method=';
Ext.define('App.model.OperationModel', {
    extend : 'Ext.data.Model',

    fields : [
        ...
    ],    
     proxy: {
            actionMethods: {
                create : 'POST',
                read   : 'POST',
                update : 'POST',
                destroy: 'POST'
           },
            type: 'ajax',
            //url: 'app/data/operation.json',                    
            api: {
                create:     urlRoot + 'Create',
                read:       'app/data/operation.json?model=Operation&method=' + 'Read',
                update:     urlRoot + 'Update',
                destroy:    urlRoot + 'Destroy'
            },
            reader: {

                type: 'json',
                metaProperty: 'meta',
                rootProperty: 'data',
                idProperty: 'id',
                totalProperty: 'meta.total',
                successProperty: 'meta.success'
            },
            writer: {
                type: 'json',
                encode: true,
                writeAllFields: true,
                rootProperty: 'data',
                allowSingle: false

            }
        }
}); 

当我创建一个新记录时,“创建”操作将发送到服务器,该记录创建成功,但是之后我想重新加载存储,然后执行读取操作并 除了其他所有内容,还可以更新网格本身。但这不起作用:

storeOperat.reload();//does not work!
gridOperat.getView().refresh();//does not work! 

更新

当我在gridOperat.getStore();而不是wind.getViewModel().get('Operations');上更改get存储时,reload()和refresh()方法开始起作用:

//var storeOperat = wind.getViewModel().get('Operations');
        var gridOperat = Ext.ComponentQuery.query('operation-grid')[0];
        var storeOperat = gridOperat.getStore();
        var record = form.getRecord(), values = form.getValues();
       ...
            if(Ext.Object.isEmpty(record)){                  

                model = storeOperat.insert(0, values);  
                storeOperat.add(model);
                storeOperat.sync();
                storeOperat.reload();
                gridOperat.getView().refresh();
...

为什么接收存储wind.getViewModel().get('Operations');方法  reload()gridOperat.getView().refresh()不起作用?

0 个答案:

没有答案