2011-12-28 11 views
0

、私はパッケージ作成しました:だけのFlexモバイルで始めたのFlex Flexのモバイルのパッケージの4.6権使用

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> 

そして、2番目のビュー:

<?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を、dataProから使用する列の名前に設定することが重要であることを知りましたヴィーダー。返された配列から正しい列を取得する他の方法はありますか?

全体:これはFlex Mobileのパッケージを使用するための正しいアプローチですか?

答えて

1

リストを取得する別の方法は、リストに対してカスタムアイテムレンダラーを作成することです。

カスタムアイテムレンダラー内では、必要な情報を表示するためのロジックを提供できます。

詳細についてはをお読みください。

この記事は、アイテムレンダラーだけでなく、パフォーマンスにも役立ちます。

2番目の質問では、パッケージの名前空間を意味しますか?

もしそうなら、あなたは '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(クラス)

+0

あなたは私がサービスは、リモート・データへの接続に使用されている知っている...ここに暗闇の中で私を残しました。このSqliteデータベースはローカルです(将来、Webサービスと同期する必要があります)。私は、データで物事を行うためのオブジェクト指向の方法を作成しようとしました。できます。しかし、私がもっとうまくやれば、私はshureのためになります – Klaaz

+0

遅れて申し訳ありません...それは問題ではありません。現時点では、「コミュニケーションの層」と言う言葉として「サービス」という言葉を使っています。外部エンティティ。それは問題ではないウェブサービス、データベースまたはクラスファクトリと通信する 'サービス'である可能性があります。その身体のようにそのような: "私はあなたの*サービス*" :) – tony

関連する問題