我有一個列表顯示我創建的SQlite數據庫的內容。但是,當我運行該功能從數據庫中刪除用戶選擇的項目之一時,項目仍會顯示,直到我刷新視圖(現在單擊「主頁」並重新進入視圖)。我怎樣才能讓列表在用戶刪除項目時自動更新?如何從數據庫刪除項目時動態更新列表
這是我的刪除功能和列表代碼:
protected function getAllcards():void // retrieve the cards from the DB and display
{
var stmt:SQLStatement = new SQLStatement();
var conn:SQLConnection = new SQLConnection();
stmt.sqlConnection = conn;
conn.open(File.applicationStorageDirectory.resolvePath("FlashCards.db"));
stmt.text = "SELECT cTitle FROM cardItems";
stmt.execute();
myCardsList.dataProvider = new ArrayCollection(stmt.getResult().data);
}
protected function myCardsList_creationCompleteHandler(event:FlexEvent):void //executed when the List completes loading
{
getAllcards();
}
protected function deleteButton_clickHandler(event:MouseEvent):void // pushed delete button
{
if(myCardsList.selectedItem != null)
{
var stmt:SQLStatement = new SQLStatement();
var conn:SQLConnection = new SQLConnection();
stmt.sqlConnection = conn;
conn.open(File.applicationStorageDirectory.resolvePath("FlashCards.db"));
stmt.text= "DELETE FROM cardItems WHERE cTitle = ?";
stmt.parameters[0] = myCardsList.selectedItem.cTitle;
stmt.execute();
refresher();
}
}
私有函數複習():無效 {VAR 語句:=的SQLStatement新的SQLStatement(); var conn:SQLConnection = new SQLConnection(); stmt.sqlConnection = conn; conn.open(File.applicationStorageDirectory.resolvePath(「FlashCards.db」)); stmt.text =「SELECT * FROM cardItems」; //刷新列表在這裏? stmt.execute(); myCardsList.dataProvider = new ArrayCollection(stmt.getResult()。data); }
列表:
<s:List id="myCardsList" x="10" y="10" left="0" right="0" top="0" bottom="0" width="1004"
height="500"
creationComplete="myCardsList_creationCompleteHandler(event)" enabled="true">
<s:itemRenderer>
<fx:Component>
<s:MobileItemRenderer label = "{data.cTitle}"/> // The Application is a mobile app
</fx:Component>
</s:itemRenderer>
</s:List>
感謝您的幫助! =)
我編輯的運算來提供信息。謝謝。 – Jordan 2011-02-26 01:43:18
當我嘗試使用refresh()時,出現編譯器錯誤(未定義的方法)。也許是因爲這是一款手機應用程序? – Jordan 2011-02-26 01:45:46
我得到它的工作。將工作代碼放在最上面。 – Jordan 2011-02-26 03:35:14