Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select items by class in Alloy Titanium

In Alloy Titanium, I can access XML elements with their id $.element_id but how do I get elements by their class ?

I have

<View id="main" layout="horizontal" horizontalWrap="true">
    <Button left="4%" width="125dp" height="125dp" backgroundImage="menus/woodblock.png"></Button>
    <Button left="13%" width="125dp" height="125dp" backgroundImage="menus/woodblock.png"></Button>
    <Button class="top30" left="4%" width="125dp" height="125dp" backgroundImage="menus/woodblock.png"></Button>
    <Button class="top30" left="13%" width="125dp" height="125dp" backgroundImage="menus/woodblock.png"></Button>
    <Button class="top30" left="4%" width="125dp" height="125dp" backgroundImage="menus/woodblock.png"></Button>
    <Button class="top30" left="13%" width="125dp" height="125dp" backgroundImage="menus/woodblock.png"></Button>
</View>

And I want to get all class="top30"

like image 421
Kalzem Avatar asked Mar 19 '23 14:03

Kalzem


1 Answers

There is no way in Alloy to access views directly by using their class except by iterating over all possible views on the screen and checking their className value.

If all your views with class="top30" are children of the same view you can try using Titanium.UI.View.children property:

var i, view
for (i in $.main.children) {
    view = $.main.children[i];
    if (view.className === 'top30') {
        /* Do your operation here */
    }
}
like image 165
daniula Avatar answered Apr 29 '23 23:04

daniula