扩展DataGrid组件,并向其添加按钮
我想用 mxml 扩展 Flex 中的标准 DataGrid 组件。但我想在组件的底部添加按钮。我尝试过以下操作,但它不起作用...
我是否将按钮添加到了错误的元素?
<mx:DataGrid xmlns:fx = "http://ns.adobe.com/mxml/2009"
xmlns:mx = "library://ns.adobe.com/flex/mx"
xmlns:s = "library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
override protected function createChildren():void
{
super.createChildren();
listContent.addChild(button);
}
]]>
</fx:Script>
<s:Button id="button" label = "asdasdas"/>
</mx:DataGrid>
I'd like to extend the standard DataGrid component in flex with mxml. But I want to add buttons to the bottom of the component. I've tried attempting the following but its not working...
Am I adding the Button to the wrong element?
<mx:DataGrid xmlns:fx = "http://ns.adobe.com/mxml/2009"
xmlns:mx = "library://ns.adobe.com/flex/mx"
xmlns:s = "library://ns.adobe.com/flex/spark">
<fx:Script>
<![CDATA[
override protected function createChildren():void
{
super.createChildren();
listContent.addChild(button);
}
]]>
</fx:Script>
<s:Button id="button" label = "asdasdas"/>
</mx:DataGrid>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要定义“不工作”!您遇到编译器错误吗?或者运行时错误?或者按钮只是没有显示?我假设是后者。
DataGrid 没有任何定位或布局其子项的机制。您的按钮的高度和宽度很可能为零,并且位于位置 0,0;使其有效地隐形。许多 Flex 容器类都能够调整其子级的大小和位置;但 DataGrid 不是容器,并且不提供内置功能。它主要侧重于使用列数组。
您将需要重写 updateDisplayList() 来定位该函数。很可能您需要在此过程中对 commitProperties() 和measure() 进行更改。您可能还需要重新调整列的位置和大小,以免干扰新按钮。如果东西被锁在私有方法中(这很可能),那么你的日子就不那么有趣了。
请阅读 Flex 组件生命周期方法以了解更多信息,并查看DataGrid 代码来弄清楚它的作用。
您可能会更轻松,只需将按钮和 DataGrid 放入容器中,并将该容器视为单个实体,而不是尝试在 DataGrid 内部渲染 Button。
You need to define "Not working"! Are you getting compiler errors? Or runtime errors? Or is the button just not showing up? I'll assume the latter.
The DataGrid does not have any mechanism for positioning or laying out it's children. Your button most likely has a height and width of zero and resides at position 0,0; making it effectively invisible. Many Flex container classes have the ability to size and position their children; but the DataGrid is not a container and does not provide built in functionality for that. It focuses, primarily, on working with the columns array.
You will need to override the updateDisplayList() to position the function. Quite possibly you will need to make changes to commitProperties() and measure() along the way. You may also need to re-work how the columns are positioned and sized as to not interfere with your new button. If stuff is locked away in private methods (which is probable) then you're in a for a not-so-fun-time.
Read up on the Flex Component LifeCycle methods for more information and also review the DataGrid code to figure out what it does.
You may have an easier time just putting the button and DataGrid in a container, and treating that container as a single entity instead of trying to get a Button renderered inside of the DataGrid.
知道了。我所需要做的就是替换 listContent.addChild(button);与...
parent.addChild(button);
谢谢!
Got it. All I needed to do was replace listContent.addChild(button); with...
parent.addChild(button);
Thanks!