这是一个灵活的新手。我已经测试了来自的“答案 2”代码
但我对其进行了修改:抛出一个按钮,其目的是在被点击后用数据填充列表;结果是半成功,取回了列表中的“[object Object]”而不是数据;如何克服这个问题?Flex是4.6,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
title="">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:layout>
<s:VerticalLayout paddingTop="10" paddingLeft="10"/>
</s:layout>
<fx:Script>
<![CDATA[
import flash.data.SQLConnection;
import flash.data.SQLStatement;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import mx.collections.ArrayCollection;
private function getData():ArrayCollection
{
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = new SQLConnection();
stmt.sqlConnection.open(File.applicationStorageDirectory.resolvePath("assets/test.sqlite"));
stmt.text = "SELECT one, two FROM zero";
stmt.execute();
var result:Array = stmt.getResult().data;
resultArr = new ArrayCollection();
if (result)
{
resultArr.source = result;
}
return resultArr;
}
[Bindable]private var resultArr:ArrayCollection = new ArrayCollection();
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
getData();
}
]]>
</fx:Script>
<s:Button label="OK" click="button1_clickHandler(event)"/>
<s:List width="302" height="234" dataProvider="{resultArr}"></s:List>
</s:View>
感谢任何想帮助我的人。