Sqlite Flex 4.6在Flex Mobile中正确使用软件包
刚开始使用Flex Mobile,我创建了一个软件包:Sqlite Flex 4.6在Flex Mobile中正确使用软件包,sqlite,mobile,flash-builder,packages,Sqlite,Mobile,Flash Builder,Packages,刚开始使用Flex Mobile,我创建了一个软件包: package valueObjects { import flash.data.SQLConnection; import flash.data.SQLStatement; import flash.filesystem.File; import mx.collections.ArrayCollection; import mx.collections.ListCollectionView;
package valueObjects
{
import flash.data.SQLConnection;
import flash.data.SQLStatement;
import flash.filesystem.File;
import mx.collections.ArrayCollection;
import mx.collections.ListCollectionView;
public class Dbsql
{
public var connection:SQLConnection;
public var result:ArrayCollection = new ArrayCollection();
public var sqlConnection:SQLConnection;
public var brand:String;
public function Dbsql()
{
}
public function listBrands():Array
{
var sqlConnection:SQLConnection;
sqlConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirectory.resolvePath("assets/db.sqlite"));
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text =
"SELECT HoofdGroep FROM products " +
"GROUP BY HoofdGroep " +
"ORDER BY HoofdGroep ASC ";
stmt.execute();
var result:Array = stmt.getResult().data;
return result;
}
public function listGroups(brand:String):Array
{
var sqlConnection:SQLConnection;
sqlConnection = new SQLConnection();
sqlConnection.open(File.applicationStorageDirectory.resolvePath("assets/db.sqlite"));
var stmt:SQLStatement = new SQLStatement();
stmt.sqlConnection = sqlConnection;
stmt.text =
"SELECT HoofdGroep, ArtikelSubGroep FROM products " +
"WHERE HoofdGroep = '" + brand + "' " +
"GROUP BY ArtikelSubGroep " +
"ORDER BY ArtikelSubGroep ASC ";
stmt.execute();
var result:Array = stmt.getResult().data;
return result;
}
}
}
主视图:
<?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="Aurum Sales" initialize="init()"> <!--initialize="init()"-->
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import valueObjects.Dbsql;
import mx.collections.ArrayCollection;
protected function init():void
{
var getClass:Dbsql = new Dbsql();
list.dataProvider = new ArrayCollection(getClass.listBrands());
}
]]>
</fx:Script>
<s:List id="list" x="0" y="0" width="100%" height="100%" labelField="HoofdGroep" change="navigator.pushView(GroupView, list.selectedItem)">
</s:List>
</s:View>
第二种观点:
<?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="{data.HoofdGroep}" initialize="init(data.HoofdGroep)">
<fx:Declarations>
</fx:Declarations>
<s:navigationContent>
<s:Button click="navigator.popView()">
<s:icon>
<s:MultiDPIBitmapSource source160dpi="@Embed('assets/arrow_left_24.png')"
source240dpi="@Embed('assets/arrow_left_48.png')"
source320dpi="@Embed('assets/arrow_left_64.png')"/>
</s:icon>
</s:Button>
</s:navigationContent>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import valueObjects.Dbsql;
protected function init(HoofdGroep:String):void
{
var getClass:Dbsql = new Dbsql();
list.dataProvider = new ArrayCollection(getClass.listGroups(HoofdGroep));
}
]]>
</fx:Script>
<s:List id="list" x="0" y="0" width="100%" height="100%" labelField="ArtikelSubGroep">
</s:List>
</s:View>
我刚刚发现,将列表的labelField设置为要从数据提供程序使用的列的名称非常重要。是否有其他方法可以从返回的数组中获取正确的列
总的来说:这是Flex Mobile中使用软件包的正确方法吗?另一种让列表显示不同值的方法是为列表创建自定义项目呈现器 在自定义项呈现器中,您可以提供任何逻辑以您想要的方式显示信息 欲了解更多信息,请阅读 本文不仅将帮助您使用项目渲染器,而且还将帮助您提高性能 现在来看第二个问题,您是指包名称空间吗 如果是这样,我看到您正在创建一个“valueObjects”包,并放置一个看起来不像valueObject的类。这个类DBsql处理数据库连接逻辑,也许“服务”名称更好。例如: com.productName.vo这将是值对象的根文件夹 com.productName.vo.ProductVO(类) com.productName.vo.ClientVO(类) 该模型的关键技术 com.productName.service(文件夹) com.productName.service.ProductService(类)
com.productName.service.ClientService(类)您让我在这里蒙在鼓里。。。我知道服务是用来连接远程数据的。这个Sqlite数据库是本地的(将来应该与Web服务同步)。我试图创建一种面向对象的方法来处理数据。它起作用了。但当我能做得更好时,我会为舒尔睿的迟来回应。。。没关系,我们现在用“服务”这个词来表示“通信层”,不管它是本地实体还是外部实体。它可以是一个与Web服务、数据库或类工厂通信的“服务”,这无关紧要。就像有人说:“我为你服务”: