I have a portion of my layout that is dynamically generated via js. From within main I create a new instance of the object and pass it the views that I would like to generate dynamically. The following is about the simplest example I can create.
main.js
var dynamicContent = new dynamicContent($.dynamicHeader,$.dynamicContent,$.dynamicFooter,$);
dynamicContent.js
function dynamicContent(header,content,footer,main){ var main = main; footer.add(createButton("back_footer","0%","100%","100%",close)); disableButton("back_footer"); function createButton(id,left,width,height,callBackFunction){ var button = Ti.UI.createButton({ callBackFunction: callBackFunction, left: left, width: width, height: height, id: id, enabled: true, backgroundColor: Alloy.Globals.bColor, backgroundSelectedColor: Alloy.Globals.bsColor }); button.addEventListener('click', function(){ if(enabled) this.callBackFunction(); }); return button; } function close(){ //this contains code to close something } function disableButton(id){ main.id.enabled = false; main.id.backgroundColor = Alloy.Globals.bGray; main.id.backgroundSelectedColor = Alloy.Globals.bGray; } }Using this process I can generate exactly what I want to see...
Since I'm not in main.js "$" is not defined so I pass it in object creation. The problem is I cannot access the items by "id" as they are undefined in the "$" scope, so calling "disableButton("back_footer");" throws undefined. Are items only added to the "$" if they are created via xml?
Is there a way for me to access these dynamic elements other than hard coding them into a variable? If I can't find a good solution I guess I will resort to pushing them onto an array and incrementing through it until I find the one that I want to modify. While that will work it doesn't seem like the correct solution...