在 Alloy Titanium 中,我可以使用 ID $.element_id
访问 XML 元素。但我如何按他们的类(class)获得元素?
我有
<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>
我想得到所有
class="top30"
最佳答案
除了遍历屏幕上所有可能的 View 并检查它们的 className
之外,Alloy 没有办法通过使用它们的类直接访问 View 。值(value)。
如果您的所有意见与 class="top30"
您可以尝试使用 Titanium.UI.View.children 的相同 View 的 subview 属性(property):
var i, view
for (i in $.main.children) {
view = $.main.children[i];
if (view.className === 'top30') {
/* Do your operation here */
}
}
关于titanium - 在合金钛中按等级选择项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23679467/