Results 1 to 5 of 5

Thread: Cloning current config component

  1. #1

    Default Cloning current config component

    Hi all,

    I got the following situation. I create some components dynamically which are inserted after the viewport has been rendered. This is all successful. But when I try to insert such a component in 2 different panels, only the last one gets inserted.

    This is just how ExtJS works, because the child component gets a reference to his parent. When you try to add this component to another parent, it checks whether it already has a parent, if so, ExtJS deletes the child from the initial parent and adds it to the new parent.

    Now my actual question, is there any way to clone a component with the current config?
    I don't mean the cloneConfig() method, because this one uses the initial config and not the current one.

    I tried copying it through Ext.apply(copyOfComponent, component) but without success.


    Thanks in advance,

    Nick

  2. #2
    Sencha Premium User Tim Toady's Avatar
    Join Date
    Feb 2010
    Location
    Pennsylvania
    Posts
    579

    Default

    If possible, it is better to define the component as a class and create two instances than to try to go that route.

  3. #3

    Default

    Quote Originally Posted by Tim Toady View Post
    If possible, it is better to define the component as a class and create two instances than to try to go that route.
    Well this is not possible for me. I add components dynamically. And I need to copy the configuration including the dynamically added components.

  4. #4
    Sencha Premium User Tim Toady's Avatar
    Join Date
    Feb 2010
    Location
    Pennsylvania
    Posts
    579

    Default

    If you can't define a class and instantiate it when you need them and you can't use cloneConfig, you are really only left with hacky solutions. Instead of trying to apply an entire object to your new instance, can you determine which properties you actually need? This is a strange issue to me. Can you explain in more detail what you are trying to do?
    Last edited by Tim Toady; 16 Oct 2012 at 6:07 AM. Reason: Removed cloneConfig suggestion after rereading first post

  5. #5
    Sencha User Cisco Kid's Avatar
    Join Date
    Apr 2017
    Location
    San Jose, CA
    Posts
    6

    Default

    Quote Originally Posted by Tim Toady View Post
    If you can't define a class and instantiate it when you need them and you can't use cloneConfig, you are really only left with hacky solutions. Instead of trying to apply an entire object to your new instance, can you determine which properties you actually need? This is a strange issue to me. Can you explain in more detail what you are trying to do?
    I have the exact same issue! It is not strange at all. I have a large number of fieldsets in a template used for configuring hardware, all set to 'hidden: true', and then based on the list of itemId's dynamically created as a result of an AJAX call (based on what hardware is detected), I show only the fields that the AJAX request tells me to. Many of these fieldsets can be duplicated (the original template has one of each fieldset, but a '+' button allows users to add/clone more of some of the fieldsets that allow multiple items). But, when using cloneConfig, all the fieldset's fields are hidden: true because they use the original config. Your cloneConfig method needs a configuration property of something like 'useCurrentConfig: true', to ignore the original config and go with the current one.

Posting Permissions

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