2015-07-02 41 views
0

我遇到了鈦合金的問題。我似乎無法訪問在控制器的XML中聲明的3d級嵌套對象。鈦合金不能訪問第三級嵌套對象

這是在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> 

這是代碼來自控制器的線:

$ .instruction.visible = FALSE;

,這是錯誤它給了我:

消息= 「undefined是不是一個對象(計算 '$ .instruction.visible =假')」;

+1

我可以用你的代碼思考的一個問題是你正在使用scrollview的集合;所以基本上,scrollview內的內容循環的次數與reportDetails模型中的行次數相同。因此'id =「指令」'也是多次創建的(即rows.length);所以當你試圖在控制器中獲取這個ID時,它可能會感到困惑,因爲一個XML文件應該有唯一的ID。 – turtle

+0

如果你能解釋你的業務邏輯;我會盡力幫忙。 – turtle

回答

1

@Turtle是正確的,數據綁定父元素(使用dataCollection)內的ID不能用於通過$.<id>訪問它們,因爲會有多個實例。

+0

我可以以某種方式使用我在html =「{agentInstructions}中用作值的」agentInstructions「參數的值來控制」指令「元素的可見參數嗎? ...是否有可能使用類似adobe flex .visible =「{agentInstructions!==''}」的東西? –

+0

您應該添加一個'dataTransform'屬性和一個轉換函數的名稱,該函數接受一個模型並返回任何額外/更改的屬性。然後在視圖中使用這個屬性與可見=「{isVisible}」 –

+0

雖然不是很靈活,它工作得很好,非常感謝。順便提一下,關於綁定的另一個問題是:如何在不可見時隱藏這個「指令」視圖?將可見參數綁定到函數,例如隱藏視圖的函數。 –