Abdul Aleem
Abdul Aleem

Reputation: 709

Appcelerator Titanium Alloy | How to access element of other class

In Alloy Titanium, I can access XML elements with their id $.element_id but how can I get elements of other class? or xml?

EDIT

I have two files. 1. file1.js, file1xml.xml 2. file2.js, file2xml.xml

In File1.js i want to access the variable of file2xml.xml. how can i achieve this?

Upvotes: 1

Views: 643

Answers (3)

Swanand
Swanand

Reputation: 1138

if you have required file2.xml in file1.xml like

<Require src="common/viewToolBar" id="viewToolBar"/>

then you can get the element with the id in file1.js like

$. viewToolBar.getView('viewSynch').visible = false;

link for more details

Upvotes: 1

arun
arun

Reputation: 107

You can use Require tag in alloy with an Id and you can access its elements as below.

**File1.xml**

<Alloy>
<View>
    <Label id="labelId">Middle</Label>
</View></Alloy>


**File2.xml**

<Window>
    <Require src="File1" id="File1View" type="View"/>
    <View id="header"><Label id="headerText">Header</Label></View>
    <View id="nav">
        <Label class="navButton" onClick="openTab" controllerName="home">Home</Label>
        <Label class="navButton" onClick="openTab" controllerName="news">News</Label>
        <Label class="navButton" onClick="openTab" controllerName="info">Info</Label>
        <Label class="navButton" onClick="openTab" controllerName="more">More</Label>
    </View>
</Window> 

**File2.js**

$.File1View.labelId.text = "hi";

Upvotes: 0

Fokke Zandbergen
Fokke Zandbergen

Reputation: 3866

Anything with an id can be accessed:

file1.xml

<Alloy>
  <View id="myView" />
</Alloy>

file2.js

var ctrl1 = Alloy.createController('file1');
ctrl1.myView.backgroundColor = 'red';

Upvotes: 2

Related Questions