0

使用 Adob​​e Flash Builder 4.6

下面的代码是我用来尝试让 actionscript 从 sqlite 表中填充列表的代码。它带回了正确数量的记录,但结果显示为:[object Object] [object Object] [object Object]

有人可以告诉我我可能做错了什么吗?

                    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);
            }
        }
4

2 回答 2

0

您需要将 labelField 设置为您的列表中的一个字段名称,以便它可以出现在列表中。在列表类型的声明中:labelField = "txtState",您将从该字段中获取信息。

于 2014-04-01T17:55:04.507 回答
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)
    }
}
于 2012-08-30T22:56:32.443 回答