我获取数据的方式是通过回调函数[processclinicResults],
并将数组Collection提供给值对象_ClinicVO。
我有一个问题,我无法通过getTableContent函数直接获取返回arrayCollection,我试图在
之后返回值
但它返回null。
有谁知道如何轻松获取阵列? 每次我使用类似的函数时,我都不想声明变量。或者我必须覆盖[clinicData]?
public function getTableContent( resultHandler:Function, faultHandler:Function = null ):void
{
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text = 'SELECT * FROM Clinic;';
stmt.itemClass = ClinicVO;
stmt.addEventListener( SQLEvent.RESULT,
function ( event:SQLEvent ):void {
resultHandler.call( this, new ArrayCollection( stmt.getResult().data ) );
});
stmt.addEventListener( SQLErrorEvent.ERROR, faultHandler == null ? sqlErrorHandler : faultHandler );
stmt.execute();
}
public function errorConnectingToTable(evt:SQLErrorEvent):void {
trace("Error getting information from DB");
}
protected function processClinicResults(resultsArray:ArrayCollection=null):void {
if (resultsArray == null) {
trace("DB has NO data");
//there is no data
} else {
clinicData = resultsArray;
}
}
答案 0 :(得分:0)
我建议你像我一样使用Flex ORM和responders来访问本地数据库:
private var entityManager:EntityManager = EntityManager.instance;
public var LocalDBSqlConnection:SQLConnection;
LocalDBSqlConnection = new SQLConnection();
LocalDBSqlConnection.open(LocalDBFile);
public function loadClinic(responder:IResponder):void
{
var clinics:Array = entityManager.query("SELECT * FROM Clinic") as Array;
responder.result(new ArrayCollection(clinics));
}
某处称之为:
loadClinic( new mx.rpc.Responder(onResult, onError));
Handelers:
private function onResult(data:Object):void
{
YourData = data as ArrayCollection;
}
private function onError(info:Object):void
{
}
我很抱歉,如果这不是你正在寻找的方式=)