EXT JS Store's Proxy: readers and writers

前端 未结 2 1340
一个人的身影
一个人的身影 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');
            }
        }
    });
    
    0 讨论(0)
  • 2021-02-06 16:35

    Actually you are correct - it will use the same url as for reader.

    Proxy is a mediator between your model/store on a client and your server code on another side. Readers are used for reading data and you could configure stuff like formatting, specify root etc. Writers are in charge of save/update requests to the server.

    Check this article: http://edspencer.net/2011/02/proxies-extjs-4.html

    0 讨论(0)
提交回复
热议问题