EXT JS Store's Proxy: readers and writers

前端 未结 2 1341
一个人的身影
一个人的身影 2021-02-06 16:12

In the documentation, i have found a store instantiated like this:

var store = Ext.create(\'Ext.data.Store\', {
    autoLoad: true,
    model: \"User\",
    proxy: {
         


        
2条回答
  •  温柔的废话
    2021-02-06 16:27

    Here is an example of a store with reader, writer and api in my App:

    Ext.define('MyApp.store.Tasks', {
        extend: 'Ext.data.Store',
        model: 'MyApp.model.Task',
        sorters : [{
           property: 'idx',
           direction: 'ASC'
        }],
        autoSync:true,
        proxy:{
            type: 'ajax',
            reader: {
                type: 'json',
                root: 'data'
            },
            writer: {
                type: 'json',
                writeAllFields : false,  //just send changed fields
                allowSingle :false      //always wrap in an array
               // nameProperty: 'mapping'
           },
            api: {
                   // read:
                    create: 'task/bulkCreate.json',
                    update: 'task/bulkUpdate.json'
                   // destroy:
            }
        },
        listeners : {
            write: function(store, operation, opts){
                console.log('wrote!');
                //workaround to sync up store records with just completed operation
                Ext.each(operation.records, function(record){
                    if (record.dirty) {
                        record.commit();
                    }
                });
            },
            update:function(){
                console.log('tasks store updated');
            }
        }
    });
    

提交回复
热议问题