钛合金的动态风格变化 [英] Dynamic style change in Titanium Alloy

查看:28
本文介绍了钛合金的动态风格变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是钛合金的新手.我正在使用 xml 标记创建一个 9X9 矩阵.如果单击单个单元格,我想更改所有单元格的背景颜色.我的问题是

I am new to the Titanium-Alloy. I am creating a 9X9 matrix using xml mark up. I want to change the background color of all the cells if I clicked on a single cell. My questions are

1) 我可以像在 jquery 中一样使用类属性吗

1) Can I use class property like in jquery

$(".col").click(function() {
    $(".col").css("background-color","red");
});

2) 我是否应该使用每个单元格的 id 属性更改背景颜色

2) Should I change the background color using id property of each and every cell

3) 是否可以为所有单元格分配一个通用的点击监听器.

3) Is it possible to assign a common click listner to all the cells.

以下是我的 xml 标记

Following is my xml markup

<View id="rowContainer" class="rowContainer">

<View id="rowHolder" class="rowHolder">

<View id="row1" class="row">

<View id="row1col1" class="col"></View>

<View id="row1col2" class="col"></View>

<View id="row1col3" class="col"></View>

<View id="row1col4" class="col"></View>

<View id="row1col5" class="col"></View>

<View id="row1col6" class="col"></View>

<View id="row1col7" class="col"></View>

<View id="row1col8" class="col"></View>

<View id="row1col9" class="col"></View>

</View>

:

:

:

<View id="row9" class="row">

<View id="row9col1" class="col"></View>

<View id="row9col2" class="col"></View>

<View id="row9col3" class="col"></View>

<View id="row9col4" class="col"></View>

<View id="row9col5" class="col"></View>

<View id="row9col6" class="col"></View>

<View id="row9col7" class="col"></View>

<View id="row9col8" class="col"></View>

<View id="row9col9" class="col"></View>

</View>


</View> // end rowHolder

</View> // end rowContainer

推荐答案

对于第一和第三部分:

不,您不能使用该技术.您必须手动将类分配给代理对象.类似的东西:

No, you cannot use that technique. You have to manually assign the classes to the proxy objects. Something similar to this:

在控制器中定义一个函数

Define a function inside your controller

function cellClickHandler(event) {
   $.addClass(event.source, 'backgroundRedColorClass');
}

在view.xml中添加:

In view.xml add:

<View id="row9col4" class="col" onClick='cellClickHandler'></View>

第二部分:

是的,这也是一种选择.假设您拥有对数组中单元格的所有引用:

Yes, this is also an option. Assuming you have all references to cells in an array:

_.each(referencesToCells, function(cell){
     $.addClass(cell, 'backgroundRedColorClass');
});

这篇关于钛合金的动态风格变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆