我有一个List,显示我创建的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();
}
}
private function refresher():void { var stmt:SQLStatement = new SQLStatement(); var conn:SQLConnection = new SQLConnection(); stmt.sqlConnection = conn; conn.open(File.applicationStorageDirectory.resolvePath( “FlashCards.db”)); stmt.text =“SELECT * FROM cardItems”; // REFRESH列表在这里? 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>
感谢您的帮助! =)
答案 0 :(得分:0)
你能否展示你为myCardsList分配数据提供者的位置?作为一个盲目的猜测,这可能会起作用:
myCardsList.dataProvider.refresh(); //Normally used to apply a sort or filter function
肖恩