Results 1 to 3 of 3

Thread: Rendering Components after initComponent finished

  1. #1
    Sencha User
    Join Date
    Feb 2017
    Posts
    9
    Answers
    1

    Default Answered: Rendering Components after initComponent finished

    Hello !

    I am using ExtJs in combination with an ASP.NET Webserver.

    What i am trying to acomplish is, to configure the GUI using a configuration that is stored in a database and gotten from the server using an Ajax call.

    I tried to do this in the initComponent section of my component, but because i want the ajax call to be asyncronous and not syncronous i have trouble adding the items of the component after applying the GuiConfiguration.

    The problem is, that the initComponent function finishes before i get the config from the server and so i cannot assign anything to the items collection of the component anymore.

    Here is an example of what i am trying to do.



    Code:
    initComponent: function() {
       var me = this;
       me.elements = [{
            xtype: 'panel',
            name: 'myPanel'
       }, ....];
       Ext.Ajax.request({			url: 'Config',
    			method: 'GET',
    			success: function (config) {
    				if (config.Components) {
    					var components = config.Components;
    					var elements = me.elements;
    					for (var i = 0; i < elements.length; i++) {
    						var element = elements[i];
    						var configObject = components.find(function (item) {
    							return item.key == element.name;
    						});
    						if (configObject) {
    							element.order = configObject.config.order;
    							element.hidden = configObject.config.hidden;
    							element.allowBlank = configObject.config.allowBlank;
    							element.readOnly = configObject.config.editable;
    						}
    					}
    					elements.sort(function (a, b) {
    						return a.order - b.order;
    					});
    				}
    				me.items = me.elements;				
    			}
    		});
        me.callParent();
    }
    The config looks like this:
    Code:
        {
    		Components: [{
    			key: 'myPanel',
    			config: {
    				hidden: false,
    				editable: false,
    				allowBlank: false,
    				order: 4
    			}
    		}]
    	}
    Does anyone have an idea?

    regards, flut

  2. Try

    Code:
    me.add(me.elements);
    instead of

    Code:
    me.items = me.elements;
    Good luck / Emil

  3. #2
    Sencha Premium Member EPV's Avatar
    Join Date
    Dec 2010
    Location
    Sweden
    Posts
    361
    Answers
    37

    Default

    Try

    Code:
    me.add(me.elements);
    instead of

    Code:
    me.items = me.elements;
    Good luck / Emil

  4. #3
    Sencha User
    Join Date
    Feb 2017
    Posts
    9
    Answers
    1

    Default

    Thank you for your reply, it worked perfectly!

Similar Threads

  1. Overriding initComponent - how to get the components?
    By Yimin Rong in forum Ext 5: Q&A
    Replies: 2
    Last Post: 15 Sep 2015, 8:35 AM
  2. Replies: 0
    Last Post: 1 Jul 2010, 4:50 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •