Results 1 to 4 of 4

Thread: Define variable name dynamically

  1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    48
    Vote Rating
    1
      0  

    Default 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

    Join Date
    Aug 2012
    Posts
    69
    Vote Rating
    1
      0  

    Default

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

  4. #3
    Sencha - Documentation Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,162
    Answers
    501
    Vote Rating
    257
      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
    1
      0  

    Default

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

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
  •