EXTJS如何让json发布方括号甚至只有1个对象

时间:2014-03-02 20:09:22

标签: json extjs

var RouteSeqStore = Ext.create('Ext.data.JsonStore', {
        model: 'RouteSeqModel',
        storeId: 'RouteSeqStore',
        autoLoad: false,
        sorters: [{
                    property: 'Route_Seq',
                    direction: 'ASC'
                }],
        proxy: {
            type: 'ajax',
            url: 'route/get-routeseq.php',
            api: {
                    destroy: 'route/delete-routeseq.php',
                    create: 'route/insert-routeseq.php',
                    //read: 'http://visual04/ModuleGestion/php/Pays.php?action=read',
                    update: 'route/update-routeseq.php',

                },
            actionMethods: 'POST',
            baseParams: {
                    _id : 0,
                },  
            reader: {
                type: 'json',
                idProperty: '_id'
            },
            writer: {
                type: 'json',
                id: '_id'

             }
        }
    });

这是我的EXTJS帖子json代码,当发布1个对象时,extjs不会有方括号

{"_id":11,"Route_Seq":1,"Location_Name":"B.STATION","Route_LocationID":"1","Route_ID":"2","id":null}

当多数组json结果具有[ ]括号时,如何让JSON发布方括号甚至只有1个对象

我期望的结果是:

[{"_id":11,"Route_Seq":1,"Location_Name":"B.STATION","Route_LocationID":"1","Route_ID":"2","id":null}]

任何解决方案?

1 个答案:

答案 0 :(得分:1)

简单:只需将作者的 allowSingle 配置设置为“false”即可。这将强制编写器始终将模型实例作为数组发送,而不管任何给定请求中是否保留了数字。请务必 check out the docs