10-29-2017 20:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-29-2017 20:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
I have a json that has a list of values that I would like to dynamically create buttons. Any ideas on creating buttons dynamically that call a generic callback with its self as the object, so that I can read the text of the selected button?
Thanks,
-Don
Answered! Go to the Best Answer.
Accepted Solutions
10-30-2017 06:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-30-2017 06:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
As for right now, creating elements dynamically is not possible. The best approach is to define your possibility domain (the max number of buttons you would ever possibly need), and then predefine them as hidden elements within the app with an ordinal identification (something like id="bt001") but set the attributes such that they won't all be rendered (perhaps width="0" height="0").
Then, each time you need a new element, you just reference some index value pointing to the next available button element and convert that to the appropriate element identifier ("bt001", "bt002", etc).
I had to take this approach for creating a barcode since I could not add rect elements to the UI after the fact. It's a little heavy, but I understand the optimizations they were likely able to make because of it. (https://github.com/bayssmekanique/fitbit-gym-card)
10-30-2017 06:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-30-2017 06:55
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
As for right now, creating elements dynamically is not possible. The best approach is to define your possibility domain (the max number of buttons you would ever possibly need), and then predefine them as hidden elements within the app with an ordinal identification (something like id="bt001") but set the attributes such that they won't all be rendered (perhaps width="0" height="0").
Then, each time you need a new element, you just reference some index value pointing to the next available button element and convert that to the appropriate element identifier ("bt001", "bt002", etc).
I had to take this approach for creating a barcode since I could not add rect elements to the UI after the fact. It's a little heavy, but I understand the optimizations they were likely able to make because of it. (https://github.com/bayssmekanique/fitbit-gym-card)
10-31-2017 18:20 - edited 10-31-2017 20:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-31-2017 18:20 - edited 10-31-2017 20:59
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thanks so much for the excellent solution!
I tried to add 176 buttons to the app, however, the app kept crashing. After dwindling down the buttons to 21 I am no longer seeing crashes. I plan to add a next page button at the bottom and that should get me what I need. 🙂

