»
S
I
D
E
B
A
R
«
Flex 的 editorDataField 之用途
10月 8th, 2008 by admin

學習如何製作 Custom Component 遇到一個不太理解的 attribute “editorDataField”. 在 O’Reilly 的 Programming Flex 2 中的例子不太反映出該 attribute 的重要性。在網上 http://flexgeek.wordpress.com/2007/04/09/tips-tricks-itemeditors-i/ 這網站亦只提及這 attribute 的值設定不當會帶來錯誤。

經過一輪試驗,好歹大概理解他的用處,大概是「告訴 Item Editor 要將修改的值以什麼形態處理」。比如在上述網站中提及的 Custom Numeric Stepper 要對 Editor 裏的值以 value 方式詮譯。我嘗試把其設為 Programming Flex 2 書第 182 頁的 Rating 元件例子中將 editorDataField 設定為 data 的做法搬到網頁例子去,結果 NumericStepper 在被調整加減數值後回傳 [object Object]。

參考 coding:

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml“>
 <mx:VBox>
  <mx:DataGrid editable=”true”>
   <mx:columns>
    <mx:DataGridColumn headerText=”Song Title” dataField=”title”/>
    <mx:DataGridColumn headerText=”Artist” dataField=”artist”/>
    <mx:DataGridColumn headerText=”Rating” dataField=”rating” itemEditor=”mx.controls.NumericStepper” editorDataField=”value”/>
   </mx:columns>
   <mx:dataProvider>
    <mx:ArrayCollection>
     <mx:Array>
      <mx:Object id=”aa” songId=”0″ title=”Astronaut” artist=”David” rating=”5″ inFavorites=”true”/>
      <mx:Object id=”bb” songId=”0″ title=”Sky” artist=”Rio” rating=”4″/>
      <mx:Object id=”cc” songId=”0″ title=”Flex” artist=”Byrun” rating=”3″/>
      <mx:Object id=”dd” songId=”0″ title=”Jp-pop” artist=”Mode” rating=”5″ inFavorites=”true”/>
     </mx:Array>
    </mx:ArrayCollection>
   </mx:dataProvider>
  </mx:DataGrid>
 </mx:VBox>
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   private function fnc(event:Event):void{
    Alert.show(this.dd.rating);
   }
  ]]>
 </mx:Script>
 <mx:Button label=”show data” click=”fnc(event)”/>
</mx:Application>

暫時發現 editorDataField 可設定為 default 的 text, value, data, selected (for checkbox), selectedColor (for colorPicker), selectedDate (for dateField) 

 這是一點心得的分享。


Leave a Reply

You must be logged in to post a comment.

»  Substance: WordPress   »  Style: Ahren Ahimsa