1. #1
    Sencha User
    Join Date
    Sep 2011
    Posts
    2
    Vote Rating
    0
    skrtl is on a distinguished road

      0  

    Default Answered: Load form with Json - how to change root parameter?

    Answered: Load form with Json - how to change root parameter?


    Hello everyone,

    I want to load a form with json-data. Instead of

    Code:
    {     success: true,     data: {         title: "Title",         name: "Name"     } }
    the json-data have the structure

    Code:
    {     success: true,     result: {         title: "Title",         name: "Name"      } }
    So I need to change the root parameter from "data"(default) to "result". I tell the reader in the formPanel to do that, but it doesn't work. I can not load the json data into the form. It seems so, that the reader isn't used?! Is it at the wrong place?

    Here is my code:

    Form:
    Code:
    Ext.define('content.StaticPages', {
        extend: 'Ext.form.Panel',
        alias: 'widget.staticpages',
        
        initComponent: function() {
            Ext.apply(this, {
                id: 'staticPageForm',
                frame:false,
                title: 'Static Page',
                bodyStyle:'padding:5px 5px 0',
                fieldDefaults: {
                    msgTarget: 'side',
                    labelWidth: 75
                },
                defaultType: 'textfield',
                defaults: {
                    anchor: '95%'
                },
                reader : Ext.create('Ext.data.reader.Json', {
                    root : 'result',
                    successProperty: 'success'
                }),
                items: [{
                    fieldLabel: 'Title',
                    name: 'title',
                    allowBlank:false
                },{
                    fieldLabel: 'Name',
                    name: 'name',
                    allowBlank:false
                }],
    
                buttons: [{
                    text: 'Save'
                },{
                    text: 'Cancel'
                }]
            });
    
            this.callParent(arguments);
        }
    });
    Controller:
    Code:
    Ext.define('controller.ContentPages', {
        extend: 'Ext.app.Controller',
        
        views: [
            'content.StaticPages',
        ],
        
        init: function() {    
            this.control({
                'panel[id=overviewtree]': {
                    itemclick: function(view, record, item, index, e, options) {
                        if (record.hasChildNodes() == false) {
    
                            var panel = Ext.ComponentMgr.get('overviewcenter');
                            panel.getLayout().setActiveItem(1);
    
                            form = Ext.ComponentMgr.get('staticPageForm');
                            form.load({
                                url: '/api/query/json/content_page.getpage',
                                params: {
                                    id: 1
                                },
                                failure: function(form, action) {
                                    Ext.Msg.alert("Load failed", action.result.message);
                                },
                                waitMsg: 'Loading...'
                            }
                        }                    
                    }
                }            
            });
        }
    });
    Thanks for help!

    stefan

  2. hi stefan,

    the formPanel itself has no reader-config, its related to the underlying Ext.form.Basic

    Note: If subclassing FormPanel, any configuration options for the BasicForm must be applied to the initialConfig property of the FormPanel. Applying BasicForm configuration settings to this will not affect the BasicForm's configuration.
    so:

    Code:
    initialConfig : {
        reader : ...
    }
    should solve your issue.

  3. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,681
    Answers
    130
    Vote Rating
    112
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  

    Default


    hi stefan,

    the formPanel itself has no reader-config, its related to the underlying Ext.form.Basic

    Note: If subclassing FormPanel, any configuration options for the BasicForm must be applied to the initialConfig property of the FormPanel. Applying BasicForm configuration settings to this will not affect the BasicForm's configuration.
    so:

    Code:
    initialConfig : {
        reader : ...
    }
    should solve your issue.
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  4. #3
    Sencha User
    Join Date
    Sep 2011
    Posts
    2
    Vote Rating
    0
    skrtl is on a distinguished road

      0  

    Default


    Hi Tobias,

    thank you for your answer! When I use the initialConfig property and also a model it works!

    Code:
    initialConfig : {
    	        	reader : Ext.create('Ext.data.reader.Json', {
    	                model: 'content.StaticPage',
    	                root : 'result'
    	            }),
    	        },
    Grüße nach München!

Thread Participants: 1

Tags for this Thread