简体   繁体   English

无法使用extjs4读取和设置Json数据

[英]Couldnt read and set Json data with extjs4

I want to read json data in extjs here is my code below. 我想在extjs中读取json数据,这是下面的代码。

What i'm doing wrong ? 我做错了什么? I'm pretty new at Extjs. 我在Extjs很新。

I think i couldn't get the json value, or couldn't properly write it down on panel. 我认为我无法获取json值,或者无法在面板上正确记录下来。

Thanks in advance. 提前致谢。

Ext.require([ 'Ext.grid.*', 'Ext.data.*', 'Ext.dd.*' ]);

    var urlGetName = '${ctx}/main/list';


    Ext.define('DataObject', {
        extend : 'Ext.data.Model',
        fields : [ 'name' ]
    });


    var storeName = Ext.create('Ext.data.Store',{   
        model:'DataObject',
        autoLoad : false,
        proxy : {
            type : 'ajax',
            actionMethods: {
                read: 'GET'
            },
                reader : {
                    type : 'json',
                    root: 'data',
                },
                api : {
                     read: urlGetName
                }
        },listeners: {
            load: function(store, records) {
                        dataa =store.getAt(0).get('data');
            }
        }
    });

    Ext.onReady(function() {

        var firstGridStore = Ext.create('Ext.data.Store', {
            model : 'DataObject',
            data : dataa
        });

        var columns = [ {
            text : "Name",
            flex : 1,
            sortable : true,
            dataIndex : 'name'
        } ];

        // declare the source Grid
        var firstGrid = Ext.create('Ext.grid.Panel', {
            multiSelect : true,
            viewConfig : {
                plugins : {
                    ptype : 'gridviewdragdrop',
                    dragGroup : 'firstGridDDGroup',
                    dropGroup : 'secondGridDDGroup'
                },
                listeners : {
                    drop : function(node, data, dropRec, dropPosition) {
                        var urlL = '${ctx}/main/list';
                        var param = data; 
                        postDataAsParamsINN({param:param},urlL,function(resp){
                            var success=resp.success;
                            if(success){
                                Ext.MessageBox.alert('succes', 'bravaa');
                            }else{
                                Ext.MessageBox.alert('error','eroross' );
                            }
                        });
                    }
                }
            },
            store : firstGridStore,
            columns : columns,
            stripeRows : true,
            title : 'First Grid',
            margins : '0 2 0 0'
        });
    });

You shouldn't use two stores to fill the one with the other. 您不应该使用两个商店来将另一个商店填满。 Delete the FirstGridStore and use the predefined remote store instead: 删除FirstGridStore并改用预定义的远程存储:

// Model
Ext.define('DataObject', {
    extend : 'Ext.data.Model',
    fields : [ 'name' ],
    idProperty: 'name'
});

// Store
var storeName = Ext.create('Ext.data.Store',{   
    model:'DataObject',
    autoLoad: true,
    queryMode: local,
    proxy: {
        type: 'ajax',
        actionMethods: {
            read: 'GET'
        },
        reader: {
            type : 'json',
            root: 'data',
        },
        api: {
            read: urlGetName
        }
    }
});

// Grid
var columns = [{
    text : "Name",
    flex : 1,
    sortable : true,
    dataIndex : 'name'
}];

        // declare the source Grid
var firstGrid = Ext.create('Ext.grid.Panel', {
    multiSelect : true,
    viewConfig : {
        plugins : {
                    ptype : 'gridviewdragdrop',
                    dragGroup : 'firstGridDDGroup',
                    dropGroup : 'secondGridDDGroup'
                },
                listeners : {
                    drop : function(node, data, dropRec, dropPosition) {
                        var urlL = '${ctx}/main/list';
                        var param = data; 
                        postDataAsParamsINN({param:param},urlL,function(resp){
                            var success=resp.success;
                            if(success){
                                Ext.MessageBox.alert('succes', 'bravaa');
                            }else{
                                Ext.MessageBox.alert('error','eroross' );
                            }
                        });
                    }
                }
            },
            store : storeName, // defined store
            columns : columns,
            stripeRows : true,
            title : 'First Grid',
            margins : '0 2 0 0'
        });
    });

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

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