Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

get to an element created by loop

$
0
0

Let's say that I create my header buttons this way, it's possible to call the active/disabled function on one of them? If not, there is any workaround for this?

Ex:

// disable headerButton (id:3, button:"more")
headerButton["more"].disabled();
Code:
var buttons = [
    {"id":1,"button":"home","side":"left"},
    {"id":2,"button":"back","side":"left"},
    {"id":3,"button":"more","side":"right"},
    {"id":4,"button":"menu","side":"right"},
    {"id":5,"button":"close","side":"right"},
    {"id":6,"button":"search","side":"right"},
    {"id":7,"button":"edit","side":"right"},
    {"id":8,"button":"view","side":"right"},
    {"id":9,"button":"view","side":"right"}
];
 
for(var n in buttons) {
    var headerButton = Ti.UI.createButton({
        zIndex:3,
        top:"3dp",
        height:"54dp",
        width:"54dp",
        borderColor:"transparent",
        borderWidth:0,
        status:false,
        visible:false,
        button:buttons[n].button,
        side:buttons[n].side
    });
 
    if(headerButton.side == "left") {
        $.header_button_left.add(headerButton);
    }
    if(headerButton.side == "right") {
        $.header_button_right.add(headerButton);
    }
 
    headerButton.addEventListener("click", function(e) {
        // case by button
    });
 
    headerButton.active = function() {
        this.setVisible(true);
        this.status = true;
        if(headerButton.side == "left") {
            this.setLeft("6dp");
        }
        if(headerButton.side == "right") {
            this.setRight("6dp");
        }
    };
 
    headerButton.disabled = function() {
        this.setVisible(false);
        this.status = false;
        this.setLeft(0);
        this.setRight(0);
    };
}

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>