如何访问另一个组件中一个mxml中的数据网格?

发布于 2024-08-07 09:29:20 字数 1623 浏览 4 评论 0原文

我的 mxml 文件中有一个数据网格,例如 samp.mxml。

<mx:DataGrid id="taskDataGrid" dataProvider="{initDG}" variableRowHeight="true" 
    editable="true" width="100%"  paddingBottom="1" paddingTop="1" height="55" > 

<mx:columns>

      <mx:DataGridColumn dataField="Select" 
                editable="true" 
                rendererIsEditor="true" 
                itemRenderer="mx.controls.CheckBox" 
                editorDataField="selected" />

      <mx:DataGridColumn dataField="TaskName"
                width="220"
                editable="true" 
                rendererIsEditor="true" 
                itemRenderer="components.taskComponent"/> //i call the component.

      <mx:DataGridColumn dataField="TaskId"
                itemRenderer="mx.controls.TextInput" />     

 </mx:columns>
 </mx:DataGrid>

在数据网格的一列中,我必须显示一个文本输入框和一个按钮。因此,我将该功能编写为单独的组件,即 taskComponent.mxml

 <mx:TextInput id="TaskName"
    editable="true" 
    text="{data.TaskName}" 
    mouseDown="addTaskRow(event);"    
   /> 

 <mx:Button id="searchTask" label="..." width="30" height="25" click="showPopUp();"/>

现在,如果我单击组件中的文本输入框,我希望添加另一个数据行。早些时候我有过这样的经历,如果我单击数据网格,就会添加一行。所以我在 samp.mxml 本身中编写了该函数。这是添加数据网格行的功能。

private function addTaskRow(event:MouseEvent):void
        {
            taskDataGrid.dataProvider.addItem(
                {

                }
            );
            taskDataGrid.height += 30; 

        }

如果我尝试在 taskComponent 文件中写入该函数,它会显示错误“访问未定义的属性 taskDataGrid”。如何在任务组件中使用数据网格?

I have a datagrid in my mxml file, say, samp.mxml.

<mx:DataGrid id="taskDataGrid" dataProvider="{initDG}" variableRowHeight="true" 
    editable="true" width="100%"  paddingBottom="1" paddingTop="1" height="55" > 

<mx:columns>

      <mx:DataGridColumn dataField="Select" 
                editable="true" 
                rendererIsEditor="true" 
                itemRenderer="mx.controls.CheckBox" 
                editorDataField="selected" />

      <mx:DataGridColumn dataField="TaskName"
                width="220"
                editable="true" 
                rendererIsEditor="true" 
                itemRenderer="components.taskComponent"/> //i call the component.

      <mx:DataGridColumn dataField="TaskId"
                itemRenderer="mx.controls.TextInput" />     

 </mx:columns>
 </mx:DataGrid>

In one of the columns of the datagrid, I have to display a text input box and a button. So I have written that functionality as a separate component,i.e, taskComponent.mxml

 <mx:TextInput id="TaskName"
    editable="true" 
    text="{data.TaskName}" 
    mouseDown="addTaskRow(event);"    
   /> 

 <mx:Button id="searchTask" label="..." width="30" height="25" click="showPopUp();"/>

Now If i click the text input box in the component, I want another data row to be added. Earlier I had it as, if I click the datagrid, a row gets added. So I wrote the function in the samp.mxml itself. This is the function to add a data grid row.

private function addTaskRow(event:MouseEvent):void
        {
            taskDataGrid.dataProvider.addItem(
                {

                }
            );
            taskDataGrid.height += 30; 

        }

If i try to write the function in the taskComponent file, it shows the error, "Access of undefined property taskDataGrid". How do I use the datagrid in the taskComponent?

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

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

发布评论

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

评论(3

眼中杀气 2024-08-14 09:29:20

trace(this.owner); 添加到文本输入的 mouseDown 并查看它跟踪的内容。如果它跟踪类似[object DataGrid]的东西,您可以使用DataGrid(this.owner)来访问taskDataGrid。

Add trace(this.owner); to the mouseDown of the text input and see what it traces. If it traces something like [object DataGrid], you can use DataGrid(this.owner) to access the taskDataGrid.

情独悲 2024-08-14 09:29:20

你不想那样做。据推测,该框和按钮添加了一个新任务。您想要做的是将新行添加到 initDG 变量中。它应该是一个ArrayCollection。然后,添加后,网格将刷新以显示新数据。

您不希望您的用户界面成为数据。您希望它反映数据。集中精力修改数据模型并让网格反映它。您可能需要进一步深入研究 Flex。重点学习有关 DataGrid、dataProvider 以及绑定如何与 ArrayCollections 配合使用的更多信息。

You don't want to do it that way. Presumably, the box and button add a new task. What you want to do is add a new row to whatever the initDG variable is. It should be an ArrayCollection. Then, when it's added, the grid will refresh to show the new data.

You don't want your UI to be the data. You want it to reflect the data. Concentrate on modifying a data model and simply let that grid reflect it. You may need to delve into Flex a little more. Focus on learning more about DataGrid, dataProvider, and how binding works with ArrayCollections.

沒落の蓅哖 2024-08-14 09:29:20

查看 Peter Ent 关于项目渲染器的文章。它的信息非常丰富,可以让您了解一些最佳实践。我已经多次提到这一点,并且我发现他所说的许多内容都非常有用...

http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html

本文特别向您展示如何使用 ListData 访问父组件 - 正确的方法:

http://www.adobe.com/devnet/flex /articles/itemrenderers_pt3_02.html

ListData 是访问父级的关键。另一个选项是从渲染器分派自定义事件。

Check out Peter Ent's article on Item Renderers. It's very informative, and lets you in on some best practices. I've referred to this many times, and I've found many of the things he says to be very useful...

http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html

This article in particular show you how to use ListData to access the parent component - the CORRECT way to do this:

http://www.adobe.com/devnet/flex/articles/itemrenderers_pt3_02.html

ListData is key for accessing the parent. The other option is to dispatch a custom Event from the renderer.

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