【发布时间】:2016-07-30 08:37:33
【问题描述】:
使用合金元素很容易定位
views.xml:
<Label id="targetID1"/>
<Label id="targetID2"/>
<Label id="targetID3"/>
controller.js:
$.targetID1.backgroundColor = "red";
$.targetID2.backgroundColor = "green";
$.targetID3.backgroundColor = "blue";
但是有没有办法将目标 ID 动态传递给函数并在该函数中设置值? 特别是,我想更改最后选择的对象的背景颜色。
例如:
var selectedObject;
function clickOnObject(e) {
selectedObject = e.source.id;
return selectedObject;
}
changeBackgroundColor(selectedObject)
//should change the background color of the selected object passed to the function
function changeBackgroundColor(id) {
$.id.backgroundColor = "orange" //this does not work
}
我找到了这个 (Select dynamically generated element by id in Titanium Appcelerator),但我不确定这是否是同一件事。
我有多个字段并使用了 switch 语句。这当然是相当麻烦的。
【问题讨论】:
标签: titanium-alloy appcelerator-titanium