2013-09-30 95 views
0

我面臨的是一個可疑的問題,它不能在邏輯上是真實的。在保存模型中,表格中的一些元素隱藏。保存模型隱藏tableview中的imageview

這裏是視圖代碼noteRow.xml

<Alloy> 
    <TableViewRow id="noteRow"> 
     <View class="noteRowSeperator"></View> 
     <View id="noteRowContainer"> 
      <View class="noteSideBox"> 
       <ImageView id="noteStatus" onClick="toggleStatus"></ImageView> 
      </View> 
      <View class="noteContentBox"> 
       <Label class="noteDescription" text="{description}"/> 
      </View> 
     </View> 
     <View class="noteRowSeperator"></View> 
    </TableViewRow> 
</Alloy> 

這裏是控制器代碼noteRow.js

var moment = require('alloy/moment'); 

var id; 
if ($model) { 
    id = $model.id; 
    if ($model.get('done')) { 
     $.noteRowContainer.opacity = 0.5; 
     $.noteStatus.image = '/images/status_completed.png'; 
    } else { 
     $.noteRowContainer.opacity = 1; 
     $.noteStatus.image = '/images/status_not_completed.png'; 
    } 
} 

function toggleStatus(e) { 
    alert(id); 
    var note = Alloy.Collections.note.get(id); 

    note.set({ 
     "done": note.get('done') ? 0 : 1, 
     "completed_at": moment().format('X'), 
     "updated_at": moment().format('X') 
    }).save(); 
} 

當模型保存所有ImageView ID爲noteStatus只是隱藏在所有的tableview tablerows。無法弄清楚爲什麼它有問題。請指導我對其進行分類。

應用類型:移動 鈦SDK:3.1.2 平臺:安卓(Gynemotion)(也是我的設備GALAXY SII上) 平臺版本:4.1.1

+0

你有沒有嘗試添加一個按鈕到錶行和按鈕的單擊事件保存模型?只是爲了測試。 –

+0

我試過了,但仍然是同樣的問題。 –

回答

1

我終於想通了。問題出在view。我更新了視圖。

<Alloy> 
    <TableViewRow id="noteRow"> 
     <View class="noteRowSeperator"></View> 
     <View id="noteRowContainer"> 
     <ImageView id="noteStatus" onClick="toggleStatus"></ImageView> 
      <View class="noteContentBox"> 
       <Label class="noteDescription" text="{description}"/> 
      </View> 
     </View> 
     <View class="noteRowSeperator"></View> 
    </TableViewRow> 
</Alloy> 

意味着簡單地刪除<View class="noteSideBox">解決了這個問題。不知道如何,但它解決了:)