简体   繁体   English

删除网格中的行时出现奇怪的JSON(Ext-JS 4)

[英]Strange JSON when deleting row in grid (Ext-JS 4)

For getting selected row in grid, I use this: 为了获得网格中的选定行,我使用以下方法:

'#deleteWorkerButton': {
                click: function(me, e, eOpts){
                    var grid = Ext.ComponentQuery.query('Worker')[0];
                    var selected = grid.getSelectionModel().getSelection()[0];

                    grid.getStore().remove(selected);
                }
            }

In my store, I have url for posting this JSON but when I use json_decode I get this: 在我的商店中,我有发布此JSON的网址,但是当我使用json_decode时,我得到了以下信息:

object(stdClass) {
    id => "5";
    name => "tets";
    email => "era@sdfsa.com";
    phone => "test";
}

But I need array() , not stdClass . 但是我需要array() ,而不是stdClass

This is my store: 这是我的商店:

Ext.define('Sabrina.store.Workers', {
    extend: 'Ext.data.Store',
    fields:['id', 'name', 'email', 'phone'],
    proxy: {
        type: 'ajax',
        api: {
            create  : 'php/usuarios.php?action=insert',
            read    : '../mega_sabrina_cake/workers/index',
            update  : 'php/usuarios.php?action=update',
            destroy : '../mega_sabrina_cake/workers/delete'
        },
        actionMethods: {
            create  : 'POST',
            read    : 'POST',
            update  : 'POST',
            destroy : 'POST'
        },
        reader: {
            type: 'json',
            root: 'Worker',
            rootProperty: 'Worker',
            successProperty: 'success',
            messageProperty: 'message'
        },
        writer: {
            type: 'json',
            writeAllFields: true,
            root: 'data',
            encode: true
        },
    },
    autoLoad: true,
    autoSync: true
});

So, I'm using this for DELETING data. 因此,我正在使用它来删除数据。 What can I do with my store to get a "NORMAL" array when json_decode()? 在json_decode()时,我该如何处理我的商店以获取“ NORMAL”数组?

I think the problem is in: 我认为问题出在:

grid.getStore().remove(selected);

Just read the docs : 只需阅读文档

mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] ) 混合json_decode(字符串$ json [, bool $ assoc = false [,int $ depth = 512 [,int $ options = 0]]])
[...] [...]
assoc When TRUE, returned objects will be converted into associative arrays. assoc为 TRUE时,返回的对象将转换为关联数组。

Try adding allowSingle: false to writer configuration. 尝试在writer配置中添加allowSingle: false By default it is set to true, which means single record changes sended without array wrap. 默认情况下,它设置为true,这意味着不进行数组换行就发送单个记录更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM