开发者

How to get value of Itemrenderer

I want to get value of checkbox from the itemrenderer.I have a datagrid with a checkBox as itemrenderer as follows:

<s:DataGrid id="myGrid" dataProvider="{module_DP}" rowHeight="35" fontSize="9"  
                    x="20" y="20" width="184" height="306">
            <s:columns>
                <s:ArrayList>                     
                    <s:GridColumn headerText="Access" dataField="access">
                        <s:itemRenderer>
                            <fx:Component>
                                <s:GridItemRenderer>
                                    <s:CheckBox label="" click="Check_Click(event)" selected="@{data.access}" horizontalCenter="0"/>
                                </s:GridItemRenderer>
                            </fx:Component>
                        </s:itemRenderer>
                    </s:GridColumn>
                开发者_Python百科</s:ArrayList>
            </s:columns>
        </s:DataGrid>

The Check_Click() method:

public function Check_Click():void{
trace(I want to get the value of clicked checkbox..in this case "access")
}

I cant figure out the code that I need to put in the trace. Can someone advise?


You can try:

<s:CheckBox label="" click="Check_Click(event)" selected="@{data.access}" horizontalCenter="0"/>


public function Check_Click(event:MouseEvent):void{
   var cb:Checkbox = event.target as CheckBox
   trace(cb.selected);
}

The post title was asking a slightly different question "How to get value of Itemrenderer". Access the data property within the renderer, like you do with {data.access}.

To access it from outside:

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

      import spark.components.gridClasses.IGridItemRenderer;
      private function onGridInitialize(event:FlexEvent):void
      {
         this.addEventListener('moduleItemChange', onModuleItemChange);
      }
      private function onModuleItemChange(event:Event):void
      {
         var item:IGridItemRenderer = event.target as IGridItemRenderer;
         if(!item || !item.data) { /* deal with this */ } 
         trace(item.data.access);            
      }
   ]]>
</fx:Script>
<s:DataGrid id="myGrid" rowHeight="35" fontSize="9"  
         x="20" y="20" width="184" height="306" 
         initialize="onGridInitialize(event)">
   <s:dataProvider>
      <s:ArrayList>         
         <fx:Object   access="true"/>
         <fx:Object   access="false"/>
         <fx:Object   access="false"/>
         <fx:Object   access="true"/>
         <fx:Object   access="true"/>               
      </s:ArrayList>
   </s:dataProvider>
   <s:columns>
      <s:ArrayList>                     
         <s:GridColumn headerText="Access" dataField="access">
            <s:itemRenderer>
               <fx:Component>
                  <s:GridItemRenderer>
                     <fx:Script>
                        <![CDATA[
                           private function Check_Click(even:MouseEvent):void
                           {
                              dispatchEvent(new Event('moduleItemChange', true));
                           }                           
                        ]]>
                     </fx:Script>
                     <s:CheckBox label="" click="Check_Click(event)" selected="@{data.access}" horizontalCenter="0"/>
                  </s:GridItemRenderer>
               </fx:Component>
            </s:itemRenderer>
         </s:GridColumn>
      </s:ArrayList>
   </s:columns>
</s:DataGrid>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜