1
views.xmlと簡単です
$.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文を使用しました。もちろんこれはかなり面倒です。
完璧!ありがとう! – user24957