2012-09-21 57 views
0

我有當前包含2次用的itemRenderer Flex的列表獲取所選值

一個Flex移動應用

視圖1具有使用的itemRenderer顯示一個ID和一個標籤 查看2只顯示一個使用數據綁定列表中的數據綁定列表itemRenderer根據數據集的內容顯示控件。

所有的數據都在SQLite數據庫舉行。

查看1是調查的名單 查看2是相對於每個調查問題清單。

當我奮力的調查ID值傳遞給SQL查詢鑑於2,使返回的數據與每個調查中的問題。

我已經一遍又一遍地dispatchEvent但不能工作了我是如何從data.surveyID相關的值傳遞給參數變量上視圖查詢數據庫。

查看1碼

   <?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" 
        xmlns:mx="library://ns.adobe.com/flex/mx" 
        title="Surveys" 
        creationComplete="listen()"> 
       <fx:Script> 
        <![CDATA[ 
         import flash.data.SQLConnection; 
         import flash.data.SQLResult; 
         import flash.data.SQLStatement; 
         import flash.events.Event; 
         import flash.filesystem.File; 
         import mx.collections.ArrayCollection; 
         import spark.events.IndexChangeEvent; 
         import spark.events.ListEvent; 
         import spark.transitions.FlipViewTransition; 
         import spark.transitions.FlipViewTransitionMode; 
         import spark.transitions.ViewTransitionDirection; 
         private var conn:SQLConnection; 
         private function get myData():ArrayCollection 
         { 
          var stmt:SQLStatement = new SQLStatement(); 
          stmt.sqlConnection = new SQLConnection(); 
          stmt.sqlConnection.open(File.applicationDirectory.resolvePath("assets/cp_db.sqlite")); 
          stmt.text = "SELECT * FROM surveys"; 
          stmt.execute(); 
          var result:Array = stmt.getResult().data; 
          if (result) 
          { 
           var list:ArrayCollection = new ArrayCollection(); 
           for (var i:int=0; i<result.length; i++) 
           { 
            list.addItem(result[i]); 
           } 
           return list; 
          } 
          else 
          { 
           return null; 
          } 
         } 
         private function workingHandler (event:Event) : void 
         { 
          trace("I'm the working handler here :) "); 
         } 
         private function listen():void{ 
         list.addEventListener("switchToDay", regularListener); 

         } 

         public var itemLabel:String; 
         private function regularListener (event:Event) : void 
         { 
          trace("I'm the regular listener" ); 
          trace(itemLabel); 
         } 
         public function conIndex(ind:int):String{ 
          return ind.toString(); 
         } 

        ]]> 

       </fx:Script> 
       <fx:Declarations> 
        <!-- Place non-visual elements (e.g., services, value objects) here --> 
       </fx:Declarations> 

       <s:List id="list" left="10" right="10" top="10" bottom="10" labelField="{data.SurveyName}" 
         click="navigator.pushView(surveyDetailView, conIndex(list.selectedIndex+1));" 
         dataProvider="{myData}" > 
        <s:itemRenderer> 
         <fx:Component> 
          <s:ItemRenderer> 
           <s:LabelItemRenderer id="surID" width="50" label="{data.surveyID}"/> 
           <s:LabelItemRenderer id="surName" x="0" width="100%" label="{data.SurveyName}" 
                click="surName.dispatchEvent(new Event('switchToDay', true,false));"/> 
          </s:ItemRenderer> 
         </fx:Component> 
        </s:itemRenderer> 
       </s:List> 
      </s:View> 

查看2碼

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" 
    xmlns:mx="library://ns.adobe.com/flex/mx" 
    title="{data}"> 
<fx:Declarations> 
    <s:SlideViewTransition id="slideTrans" direction="down" duration="300"/> 
</fx:Declarations> 
<fx:Script> 
    <![CDATA[ 
     import flash.data.SQLConnection; 
     import flash.data.SQLStatement; 
     import flash.filesystem.File; 
     import flash.filesystem.FileMode; 
     import mx.collections.ArrayCollection; 
     import spark.components.Button; 
     import spark.components.Label; 
     public var surveyIdParam:String = '1'; 
     public var myPar:String; 
     public function get myData():ArrayCollection 
     { 
      var stmt:SQLStatement = new SQLStatement(); 
      stmt.sqlConnection = new SQLConnection(); 
      stmt.sqlConnection.open(File.applicationDirectory.resolvePath("assets/cp_db.sqlite")); 

      stmt.parameters[0] = surveyIdParam; 
      stmt.text = "SELECT * FROM surveyquestions where surveyID = ?"; 
      stmt.execute(); 
      var result:Array = stmt.getResult().data; 

      if (result) 
      { 
       var list:ArrayCollection = new ArrayCollection(); 
       for (var i:int=0; i<result.length; i++) 
       { 
        list.addItem(result[i]); 
       } 
       return list; 
      } 
      else 
      { 
       return null; 
      } 
     } 
    ]]> 
</fx:Script> 
<s:List id="list" left="0" right="0" top="50" bottom="0" dataProvider="{myData} "> 
    <s:itemRenderer> 
     <fx:Component> 
      <s:ItemRenderer> 
       <fx:Script> 
        <![CDATA[ 
         import spark.components.Label; 
         private function addItem(qtype:String):void 
         { 

          if (qtype == "1") { 
           icrHeading.visible = true; 
           ti.visible=false; 
           cb.visible=false; 
          } 
          else if (qtype == "2") { 

          } 
          else if (qtype == "3") { 
           icrDetail.visible=true; 
          } 
         } 
        ]]> 
       </fx:Script> 
       <s:VGroup id="contentHolder"> 

       </s:VGroup> 

       <s:IconItemRenderer id="icr1" visible="false" x="0" width="50" 
            label="{data.QuestionTypeID}"/> 
       <s:IconItemRenderer id="icrHeading" visible="false" x="0" width="450" 
            label="{data.QuestionTitle}" color="0xff0000"/> 
       <s:IconItemRenderer id="icrDetail" visible="false" x="50" width="450" 
            label="{data.QuestionTitle}"/> 
       <s:Label id="ilbl1" x="50" width="120" added="addItem(icr1.label.toString())"/> 
       <s:TextInput id="ti" x="600" width="200" text=""/> 
       <s:CheckBox id="cb" x="550"> 
       </s:CheckBox> 
      </s:ItemRenderer> 
     </fx:Component> 
    </s:itemRenderer> 
</s:List> 
<s:Button id="btn" x="717" y="10" label="{data}" click="navigator.popView()"/> 
+0

這將有助於如果你可以指定它是什麼,你看到的是導致你認爲這是行不通的。我認爲這個問題有很多解決方案。 – badunk

回答

0

article可以幫助您將視圖之間傳遞數據。基本上,navigator.pushView接受參數