ExtJS配置存储在属性名称下编写模型列表

ExtJS configure store to write list of models under a property name

本文关键字:模型 列表 配置 存储 属性 ExtJS      更新时间:2023-09-26

我有一个这样的模型:

Ext.define('Policy', {
    extend: 'Ext.data.Model',
    fields: [
        {
            name: 'id',
            type: 'sting',
            phantom: true,
            convert: function(value, record) {
                return record.get('a') + '@' +
                    record.get('b');
            }
        },
        {name: 'a', type: 'string'},
        {name: 'b', type: 'string'}]
});

其中每条记录的PK分别为ab。商店是这样的:

Ext.define('Store', {
    extend: 'Ext.data.Store',
    model: 'Policy', 
    autoLoad: true,
    proxy: {
        type: 'rest',
        simpleSortMode: true,
        batchActions: true,
        reader: {
            type: 'json',
            root: 'data',
            idProperty: 'id'
        },
        writer: {
            nameProperty: 'mapping'
        },
        api: {
            create:'/batch',
            read: '/policies',
            update: '/batch',
            destroy: '/batch'
        }
    }
});

我如何配置存储,以便在调用store.sync()时post到/批处理,有效负载看起来像这样,只包含脏记录:

{
    "policies": [{
        "a": "AA",
        "b": "BB",
    }, {
        "a": "AAA",
        "b": "BBB"
    },...]
}

,其中有一个policies属性,在它下面是一个dirty策略数组。

您可以通过手动调用Ext.Ajax()来创建任何您想要的结构。您只需自己提交脏记录。