0

If I have a view - myCoolView - and I'd like to change the text of a button in the view, how do I do it?

Given that I know that the button is called, say, myCoolButton, and it was added to the view in some function, and now, in a different function I have access to myCoolView, how do I change the button text?

I checked the Titanium API and I cannot see a "getter" call on a view to access anything that was added to it via the add method.

4

1 回答 1

2

Use the "children" property, as documented.

// Create the views.
var myCoolView = Ti.UI.createView();
var myCoolButton = Ti.UI.createButton({
    title: 'My Cool Button',
    id: 'myButtonsID'
});
myCoolView.add(myCoolButton);

// Later, find the button.
var children = myCoolView.children;
if (children) {
    for (var i = children.length - 1; i >= 0; i--) {
        if (children[i].id === 'myButtonsID') {
            children[i].title = 'My Updated Cool Button';
            break;
        }
    }
}
于 2012-09-04T18:10:55.960 回答