2014-10-06 20 views
0

但每當我嘗試使用任何嘗試清除的tableView只是雙打,我試圖更新與更新後的數據我表視圖內容

tagsTable.setData(); 
or 
tagsTable.setData([]); 
or 
tagsTable.data = null; 

,然後使用重新申請更新的數據來清除它

tagsTable.setData(TagsData); 

它從不清理表格,因此新數據剛剛添加到表格的末尾,所以我有舊數據以及1表格中的新數據。

任何人知道最新錯誤或如何解決它?

+2

我可以看看你如何更新'TagsData'中的數據嗎?你必須在添加最新數據之前清除它'TagsData = []'... – Coyote 2014-10-06 08:08:57

回答

0

下面是一個簡單的(經典的鈦)應用程序,通過一些按鈕顯示清除並重新填充表的data屬性。我會仔細檢查你的TagsData部分/行的有效性,以確保數組中的所有內容都被正確設置。

var 
    win = Ti.UI.createWindow({ 
     title: "Table Funs", 
     layout: "vertical", 
     backgroundColor: "#ffffff" 
    }), 
    navwin = Ti.UI.iOS.createNavigationWindow({ 
     window: win 
    }), 
    table = Ti.UI.createTableView(), 
    clearButton = Ti.UI.createButton({ 
     title: "Clear Table", 
     width: Ti.UI.FILL, 
     height: 44, 
     backgroundColor: "#f4f4f4", 
     color: "red", 
     bottom: 1 
    }), 
    fillButton = Ti.UI.createButton({ 
     title: "Fill Table", 
     width: Ti.UI.FILL, 
     height: 44,   
     backgroundColor: "#f4f4f4", 
     color: "blue", 
     bottom: 1 
    }), 
    tableData = []; 

// Fill up tableData array with rows 
tableData.push(Ti.UI.createTableViewRow({ title: "Hey" })); 
tableData.push(Ti.UI.createTableViewRow({ title: "this" })); 
tableData.push(Ti.UI.createTableViewRow({ title: "is" })); 
tableData.push(Ti.UI.createTableViewRow({ title: "a" })); 
tableData.push(Ti.UI.createTableViewRow({ title: "table" })); 

clearButton.addEventListener("click", function() { 
    Ti.API.debug("Clicked clear button."); 
    table.setData(null); 
    return; 
}); 

fillButton.addEventListener("click", function() { 
    Ti.API.debug("Clicked fill button."); 
    table.setData(tableData); 
    return; 
}); 

// Fill table with our data 
table.setData(tableData); 

// Build window 
win.add(clearButton); 
win.add(fillButton); 
win.add(table); 

navwin.open();