How to duplicate an Enyo component?

Is there a way to duplicate an Enyo component? I have some generated code that is not static and therefore I cannot just instantiate a new object from it unfortunately. So is there a way to take an already created object and create or duplicate another object from it? Hopefully that makes sense. Thanks.

Comments

  • I'm not sure I'm following. Can you post a fiddle showing what you want to do?
  • edited October 2013
    sugardave, my problem is part of a bigger project that would take a while to move over to a fiddle unfortunately. But I guess I can better explain what I mean. I basically need a list that groups its components depending on the model. So lets say I already have predefined cells that look something like this:
    cell1: label, dropdown
    cell2: label, image
    Now lets say one row of the model asks for TWO cell1's and ONE cell2. But the next row might be different. Thus I don't know what I'll need until runtime, hence why I was wondering if duplicating components is possible from already created objects.

    I could easily take the model, and create a simple 1d array and just group them manually depending on group title, etc. But itd be nice to be able to leave them in a single row and toggle whatever I don't need to show or duplicate components. If that still doesn't make sense I can spend the time trying to make a simple example in a fiddle.
  • Hmm, a fiddle would help!

    But, it sort of sounds like you just need to have defined the various "cell" kinds that you might need to use and then, based on the model you're given from whatever source, determine which of those kinds you need to create/render.

    So, your model could have some property that describes what it needs:

    needs: ["cell1", "cell1", "cell2"]

    And then you can make them. Of course, I've left out the part of how/where to get the data for those kinds, but I assume it will be in whatever it is that you get this.

    Also, if you just need to make a new instance of the same kind (as opposed to an exact copy of an instance), you can get the kindName and just make a new one.
  • I've thought about that as well. Thank you very much for the input. I will work on it some more today and if I can't get it working I'll spend some time on a fiddle to show you what I need if I can't get it working. Thanks a lot sugardave. Appreciate it.
  • edited October 2013
    You could try:
    var t = enyo.kind({kind:cellKind});
    new t({});
    
    Where cellKind is the kindName for your cell types. However, I'm not sure this is the best way to accomplish what you are trying to do. If you can make a fiddle it would really help to understand your problem.
  • edited October 2013
    You can also do it on the window since enyo loads all kinds into the global namespace (one reason to use namespacing, among many).
    var t = new window[cellKind]();
    
Sign In or Register to comment.