刚开始使用Flex Mobile,我创建了一个包:
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设置为要从dataProvider中使用的列的名称非常重要。是否有其他方法可以从返回的数组中获取正确的列?
总体而言:这是Flex Mobile中使用软件包的正确方法吗?
答案 0 :(得分:1)
获取列表显示不同值的另一种方法是为列表创建自定义项呈示器。
在自定义项呈示器中,您可以提供任何逻辑以按您希望的方式显示信息。
了解更多信息,请阅读this link。
本文不仅可以帮助您使用项目渲染器,还可以使用性能。
现在针对你的第二个问题,你的意思是包命名空间吗?
如果是这样,我看到你正在创建一个'valueObjects'包并放置一个看起来不像valueObject的类。这个类DBsql处理数据库连接逻辑,也许一个'服务'名称会更好。例如:
com.productName.vo这将是值对象的根文件夹
com.productName.vo.ProductVO(class)
com.productName.vo.ClientVO(class)
为模型
com.productName.service(folder)
com.productName.service.ProductService(class)
com.productName.service.ClientService(class)