如何获取Itemrenderer的值

发布于 2024-12-05 09:22:02 字数 1208 浏览 0 评论 0原文

我想从 itemrenderer 获取复选框的值。我有一个带有 checkBox 作为 itemrenderer 的数据网格,如下所示:

<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>
                </s:ArrayList>
            </s:columns>
        </s:DataGrid>

Check_Click() 方法:

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

我无法弄清楚需要放入跟踪中的代码。 有人可以建议吗?

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>
                </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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡離愁欲言轉身 2024-12-12 09:22:02

您可以尝试:

<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);
}

帖子标题提出了一个略有不同的问题“如何获取 Itemrenderer 的值”。访问渲染器中的数据属性,就像使用 {data.access} 一样。

要从外部访问它:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文