2012-10-26 63 views
0

大家好,首先感謝您的關注和支持。我是flex世界的初學者......我想要做的事可能太簡單了,但我無法弄清楚。彈出通過列表項目之間的數據視圖

我正在練習一個簡單的移動應用程序,它利用數據庫在phpmyadmin中創建並連接到我的移動項目。我想要做的是:當我點擊任何列表項時,這個彈出下一個視圖,顯示數據庫表中所有文本輸入中所選項目的值。我知道如何在我執行的列表視圖中顯示,而是因爲我沒有做(和不想)列表項在我的其他看法,我得到一個錯誤:

protected function list_changeHandler(event:IndexChangeEvent):void 
     { 
      titleTextInput.text = list.selectedItem.title; 
      dateIntro.selectedDate = list.selectedItem.date; 
      photoTextInput.text = list.selectedItem.photo; 
      descriptionTextInput.text = list.selectedItem.description; 
     } 

但是我需要做些什麼才能在我的另一種觀點中獲得相同的結果?

該項目有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" 
    xmlns:valueObjects="valueObjects.*" 
    xmlns:detallesservice="services.detallesservice.*" add="home(event)"> 

<fx:Script> 
    <![CDATA[ 
     import mx.events.FlexEvent; 

     import spark.events.IndexChangeEvent; 
     protected function button_clickHandler(event:MouseEvent):void 
     { 
      var detalles2:Detalles = new Detalles(); 
      detalles2.title = titleTextInput.text; 
      detalles2.date = dateIntro.selectedDate; 
      detalles2.photo = photoTextInput.text; 
      detalles2.description = descriptionTextInput.text; 

      detallesService.createDetalles(detalles2); 
      detallesService.getAllDetalles(); 
     } 

     protected function list_creationCompleteHandler(event:FlexEvent):void 
     { 
      getAllDetallesResult2.token = detallesService.getAllDetalles(); 
     } 


     protected function button2_clickHandler(event:MouseEvent):void 
     { 
      detallesService.deleteDetalles(list.selectedItem.title); 
     } 

     protected function list_changeHandler(event:IndexChangeEvent):void 
     { 
      titleTextInput.text = list.selectedItem.title; 
      dateIntro.selectedDate = list.selectedItem.date; 
      photoTextInput.text = list.selectedItem.photo; 
      descriptionTextInput.text = list.selectedItem.description; 

      navigator.pushView(asyouwishView, list.selectedItem); 
     } 
    ]]> 
</fx:Script> 

<fx:Declarations> 
    <valueObjects:Detalles id="detalles"/> 
    <detallesservice:DetallesService id="detallesService"/> 
    <s:CallResponder id="createDetallesResult"/> 
    <s:CallResponder id="getAllDetallesResult2"/> 
    <s:CallResponder id="deleteDetallesResult"/> 
</fx:Declarations> 
<s:List id="list" x="1100" y="142" width="716" height="372" 
     creationComplete="list_creationCompleteHandler(event)" labelField="title" change="list_changeHandler(event)"> 
    <s:AsyncListView list="{getAllDetallesResult2.lastResult}"/> 
</s:List> 
<s:Form defaultButton="{button}"> 
    <s:FormItem label="Title"> 
     <s:TextInput id="titleTextInput" text="{detalles.title}"/> 
    </s:FormItem> 
    <s:FormItem width="800" label="Date"> 
     <s:DateSpinner id="dateIntro" displayMode="date" selectedDate="{detalles.date}"/> 
    </s:FormItem> 
    <s:FormItem label="Photo"> 
     <s:TextInput id="photoTextInput" text="{detalles.photo}"/> 
    </s:FormItem> 
    <s:FormItem label="Description"> 
     <s:TextInput id="descriptionTextInput" text="{detalles.description}"/> 
    </s:FormItem> 
    <s:Button id="button" label="CreateDetalles" click="button_clickHandler(event)"/> 
</s:Form> 
<s:Form x="18" y="950"> 
    <s:FormItem label="CreateDetalles"> 
     <s:TextInput id="createDetallesTextInput" 
        text="{createDetallesResult.lastResult as String}"/> 
    </s:FormItem> 
</s:Form> 
<s:Button id="myDelete" x="1100" y="558" label="Delete" click="button2_clickHandler(event)"/> 

這是第二個視圖:

<fx:Script> 
    <![CDATA[ 
     import spark.events.ViewNavigatorEvent; 
     protected function button_clickHandler(event:MouseEvent):void 
     { 
      // Please uncomment the below line if Data Management is enabled for Detalles and updateDetalles is used as the create function. 
      // var detalles:Detalles = new Detalles(); 
      detalles.title = titleTextInput.text; 
      detalles.date = dateIntro.selectedDate; 
      detalles.photo = photoTextInput.text; 
      detalles.description = descriptionTextInput.text; 

      updateDetallesResult.token = detallesService.updateDetalles(detalles); 
     } 
    ]]> 
</fx:Script> 

<fx:Declarations> 
    <valueObjects:Detalles id="detalles"/> 
    <detallesservice:DetallesService id="detallesService"/> 
    <s:CallResponder id="updateDetallesResult"/> 
</fx:Declarations> 

<s:actionContent> 
    <s:Button label="BACK" click="{navigator.popView();}"/> 
</s:actionContent> 

<s:Form x="70" y="68" defaultButton="{button}"> 
    <s:FormItem label="Title"> 
     <s:TextInput id="titleTextInput" text="@{detalles.title}"/> 
    </s:FormItem> 
    <s:FormItem width="766" label="Date"> 
     <s:DateSpinner id="dateIntro" displayMode="date" selectedDate="@{detalles.date}"/> 
    </s:FormItem> 
    <s:FormItem label="Photo"> 
     <s:TextInput id="photoTextInput" text="@{detalles.photo}" /> 
    </s:FormItem> 
    <s:FormItem label="Description"> 
     <s:TextInput id="descriptionTextInput" text="@{detalles.description}"/> 
    </s:FormItem> 
    <s:Button id="button" label="UpdateDetalles" click="button_clickHandler(event)"/> 
</s:Form> 

回答

0

學習和使用框架是必要的。我推薦Swizframework

Swiz中的數據綁定和事件是一件輕而易舉的事情。你會愛上它的。

+0

感謝您的建議=)我會嘗試一下,你知道一個更好的方法來學習如何使用它嗎? –

+0

只要用它做出一些東西,這是學習新東西的最佳方式。 – simmone

相關問題