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"
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 */
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With