EXT JS Store 的代理:读者和作者 [英] EXT JS Store's Proxy: readers and writers

查看:23
本文介绍了EXT JS Store 的代理:读者和作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文档中,我发现了一个像这样实例化的商店:

<前>var store = Ext.create('Ext.data.Store', {自动加载:真,模型:用户",代理人: {类型:'阿贾克斯',网址:'users.json',读者:{类型:'json',根:'用户'}}});

代理有一个 url 配置.我对读者特别感兴趣.读取器指定数据交换格式 (json) 和根 ('users').现在,换句话说,如果 store 设置为:autoLoad = true,那么 EXT JS 将与指定的 url 建立 Ajax 连接,以便 read.现在,我将如何为上面的同一家商店配置作家?有人也告诉我这个:如果我配置一个 writer,它会使用与代理中指定的相同的 url 吗?我仍然对我上面展示的代码上下文中的作者和读者感到困惑,你会帮助我使用上面的例子来展示读者和作者的配置.谢谢.

解决方案

以下是我的 App 中带有 reader、writer 和 api 的 store 示例:

Ext.define('MyApp.store.Tasks', {扩展:'Ext.data.Store',模型:'MyApp.model.Task',分拣员:[{属性:'idx',方向:'ASC'}],自动同步:真,代理人:{类型:'阿贾克斯',读者:{类型:'json',根:'数据'},作者:{类型:'json',writeAllFields : false,//只发送改变的字段allowSingle :false//总是包裹在一个数组中//nameProperty: '映射'},接口:{//读:创建:'任务/bulkCreate.json',更新:'task/bulkUpdate.json'//破坏:}},听众:{写:功能(存储,操作,选择){console.log('写了!');//使用刚刚完成的操作同步存储记录的解决方法Ext.each(operation.records, function(record){如果(记录.脏){记录提交();}});},更新:功能(){console.log('任务存储更新');}}});

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

var store = Ext.create('Ext.data.Store', {
    autoLoad: true,
    model: "User",
    proxy: {
        type: 'ajax',
        url : 'users.json',
        reader: {
            type: 'json',
            root: 'users'
        }
    }
});

The proxy has one url config. I am particularly interested in the reader. The reader specifies the data exchange format (json) and the root ('users'). Now, in other words if the store is set up to be: autoLoad = true, then EXT JS will make an Ajax connection to the url specified in order to read. Now, how would i configure a writer for that same store above? Someone also tell me about this: if i configure a writer, would it use the same url as specified in the proxy? am still confused about writers and readers in context of the code i have showed above, you would help me use the above example to show readers and writer configs. Thank you.

解决方案

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

这篇关于EXT JS Store 的代理:读者和作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆