titanium - 在合金钛中按等级选择项目

标签 titanium titanium-alloy

在 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/

相关文章:

android - Titanium 中从左到右的滑动效果

javascript - 从 webview 中更改选项卡

android - Appcelerator 钛平台 : Android/iOS Icons Structure andUse

android - Titanium android 设备 http 错误

javascript - Titanium动态样式 View

android - Titanium SDK 在 Ubuntu 12.04 上无法识别 Titanium CLI、node、alloy 或 npm

iphone - 添加导航按钮在钛合金中第一次不起作用

titanium - 如何在钛中设置请求 header

web-services - Azure:是否创建Web服务

titanium - Titanium 中的集合单例或实例有什么区别?