Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

add data to json object

Hi

Suppose I have an object call buttonlist.
How do I add more data to this object

var buttonObjects2 = null;

for (var i=0;i<12;i++)
{
buttonObjects2.add({ BG_Options[i], height:33 } );
}

doesn't work as there is no add function…

Help!

— asked April 5th 2010 by Peter Lum
  • add
  • json
  • object
0 Comments

3 Answers

  • Accepted Answer

    Hi,

    For first, you must know what you are trying to do.
    If you want to create a matrix, you must declare: var buttonObjects2 = []
    and than:

    buttonObjects2.push() or buttonObjects2[i] = receive something.

    But, you seem wanna create a button, so use this

    var buttonObjects2 = []

    for (var i=0;i<12;i++) { buttonObjects2[i] = Titanium.UI.createButton({BG_Options[i]}); buttonObjects2[i].height=33}

    — answered April 5th 2010 by Marcos Gonçalves
    permalink
    0 Comments
  • Hi Peter

    I think .push is the thing to use here.

    cheers,
    Chris.

    — answered April 5th 2010 by Chris Reed
    permalink
    0 Comments
  • push does the trick!
    Thanks!

    — answered April 6th 2010 by Peter Lum
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.