1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    0
    eaglefox12 is on a distinguished road

      0  

    Default Answered: Define variable name dynamically

    Answered: Define variable name dynamically


    Code:
    this.FirstName = Ext.create('Ext.form.TextField', {
                name: 'FirstName',
                fieldLabel: 'First Name',
                allowBlank: false
            });
    Is there a way to dynamicaly increment the firstname textbox. I tried
    Code:
    int x = 1;
    this.FirstName[x] = Ext.create('Ext.form.TextField', {
                name: 'FirstName' + x,
                fieldLabel: 'First Name' + x,
                allowBlank: false
            });
    but I get this error
    Code:
    TypeError: can't convert undefined to object
    what I am going to end up having is bunch of textbox.
    this.FirstName1, thisFirstName2, thisFirstName3.

  2. In your loop you can do something like:
    this["FirstName" + i]

  3. #2
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    62
    Vote Rating
    1
    zzhouag is on a distinguished road

      0  

    Default


    have you tried x.toString() ? the name and fieldLabel must be string

  4. #3
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,048
    Answers
    391
    Vote Rating
    185
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    In your loop you can do something like:
    this["FirstName" + i]

  5. #4
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    0
    eaglefox12 is on a distinguished road

      0  

    Default


    Quote Originally Posted by slemmon View Post
    In your loop you can do something like:
    this["FirstName" + i]
    Thank you