Search code examples
appceleratortitanium-alloyappcelerator-alloy

Duplicate an alloy object


I searched and could not find an answer, so here is my doubt,

is it possible to fetch an object and duplicate it?, like, I have this code in my view (.xml):

<View id="endereco1" class="" layout="horizontal" height="60dp" >   
  <Label class="input-left-label label-font-size label-text-align-right">CEP: </Label>
  <TextField class="textArea"></TextField>
</View>

then on my Js I would like to fetch this $.endereco1, and creat and $.endereco2, changing only the id, is it possible, like instantiating the object that was written on the view?

thank you in advance


Solution

  • underscore.js is built into the titanium sdk. why not simply use

    clone 
    
    _.clone(object) 
    Create a shallow-copied clone of the provided plain object. Any nested objects or arrays will be copied by reference, not duplicated.
    
    _.clone({name: 'moe'});
    => {name: 'moe'};