0
votes

I've ran into a problem with Titanium Alloy. I can't seem to access a 3d level nested object that is declared in the XML from the controller .

This is the layout in XML :

<Alloy>
    <Collection src="reportDetails"/>
    <Window class="container" title="Update Report Details" onClose="cleanup" >

        <View id="labels">          
            <TextArea id="jobTitle" class="title bold" editable="false"></TextArea>         
            <View class="jobTitleSecondPart" >
                <Label class='bold'>last date od service: </Label>
                <Label id="jobDate" class="stickLeft"></Label>
                <Label class='bold'>Job ID: #</Label>
                <Label id="jobId" class="stickLeft"></Label>
            </View>
        </View>
        <ActivityIndicator id="busy"></ActivityIndicator>
        <View height="Titanium.UI.FILL">
            <ScrollView  id="scrollIns" layout="vertical" dataCollection="reportDetails" dataFilter="filterFunction" height="Titanium.UI.FILL">
                <View id="instruction"> <!-- ***I am trying to access this object in the controlle***r -->
                    <Label class="title bold black">Agent Instructions :</Label>
                    <Label platform="android" id="jobInstruction" html="{agentInstructions}" class="black"   height="Titanium.UI.SIZE" />
                    <WebView platform="ios" id="jobInstruction" html="{agentInstructions}" class="black" touchEnabled="false" height="Titanium.UI.SIZE" />
                </View>
                <View id="comment">
                    <Label class="title bold black">Agent Comment :</Label>
                    <Label id="jobComment" class="black" text="{reportComment}"></Label>
                </View>
                <Require src="reportImageGallery" images="{images}"/>
            </ScrollView>
            <View id="buttons">
                <Button id="btnInsert" class="bold" onClick="showInsertReport">Insert Update Reports</Button>
            </View>
        </View>

    </Window>
</Alloy>

This is the line of code from the controller :

$.instruction.visible = false;

And this is the error it gives me :

message = "undefined is not an object (evaluating '$.instruction.visible = false')";

1
one issue which i could think with your code is that you are using collection for scrollview; so basically the content within scrollview loops as many times as the rows in your reportDetails model. Hence id="instruction" is also created multiple times (i.e rows.length); so when you try to fetch that id in controller it maybe getting confused because a xml file should have unique ids.turtle
if you can explain your business logic; i will try to help.turtle

1 Answers

1
votes

@Turtle is correct that IDs inside a data-bound parent element (using dataCollection) cannot be used to reach them via $.<id> since there would be more then one instance.