2012-06-27 152 views
0

使用Adobe Flash Builder 4.6動作從sqlite表中填充列表

下面的代碼是我正在使用的嘗試從sqlite表中獲取動作來填充列表a。它帶回正確的記錄數量,而是出了結果: [目標對象] [目標對象] [目標對象]

有人能告訴我,我可能會做錯了什麼?

    private var strGetDBName:String = "CPRInstr.db"; 
     private var strGetCurrentTableName:String = "lkStates"; 

     import flash.data.SQLConnection; 
     import flash.data.SQLResult; 
     import flash.data.SQLStatement; 
     import flash.filesystem.File; 
     import mx.collections.ArrayCollection; 

     private var conn:SQLConnection; 

     private function init():void 
     { 
      conn = new SQLConnection(); 
      conn.addEventListener(SQLEvent.OPEN, openSuccess); 
      //conn.addEventListener(SQLErrorEvent.ERROR, openFailure); 
      var dbFile:File = File.applicationDirectory.resolvePath(strGetDBName); 
      conn.openAsync(dbFile); 
     } 

     private function openSuccess(event:SQLEvent):void 
     { 
      conn.removeEventListener(SQLEvent.OPEN, openSuccess); 
      //conn.removeEventListener(SQLErrorEvent.ERROR, openFailure); 
      getData(); 
     } 

     private function getData():void 
     { 
      var select:SQLStatement = new SQLStatement(); 
      select.sqlConnection = conn; 
      //select.text = "SELECT id, txtState, txtAbbrev FROM " + strGetCurrentTableName; 
      select.text = "SELECT id, txtState FROM lkStates"; 
      select.addEventListener(SQLEvent.RESULT, selectResult); 
      //select.addEventListener(SQLErrorEvent.ERROR, selectError); 
      select.execute(); 
     } 

     private function selectResult(event:SQLEvent):void 
     { 
      var result:SQLResult = null; 
      result = event.currentTarget.getResult(); 

      if(result.data) 
      { 
       list.dataProvider = new ArrayCollection(result.data); 
      } 
     } 

回答

0

這對我有用,我試圖匹配你的變量,例如。

var result:SQLResult = select.getResult(); 
list.dataProvider = new DataProvider(result.data); 

if(result.data) 
{ 
    for(var i:int = 0; i < result.data.length; i++) 
    { 
     var tState:Object = result.data[i]; 
     trace("var1 "+tState.var1+"var2 "+tState.var2...etc) 
    } 
} 
+0

你的意思是在'selectResult()'函數內? – nalply

0

您需要的labelField設置爲您的列表中字段名稱在表中,以便它可以出現在列表中。在列表類型的聲明中:labelField =「txtState」,您將從該字段獲取信息。