Flex 4 - 当容器的子级依赖于状态时如何循环它们
Flex 的新状态重新设置了标有 includeIn/excludeFrom 的视觉项目的父级。如果我有一个包含 5 个受状态控制的子元素/元素的组 (MainGroup),是否还有办法获取对 MainGroup 子元素的引用? mainGroup.numChildren 和 mainGroup.numElements 不起作用,因为子级被重新设置了父级。最好的情况下,它们显示 1。
<s:states>
<s:State name="view1State" />
<s:State name="view2State" />
<s:State name="view3State" />
<s:State name="view4State" />
</s:states>
<s:Group id="mainGroup">
<shipping:OrderShipping id="view1"
includeIn="view1State" />
<payment:OrderPayment id="view2"
includeIn="view2State" />
<verification:OrderVerification id="view3"
includeIn="view3State" />
<confirmation:OrderConfirmation id="view4"
includeIn="view4State" />
</s:Group>
Flex's new States re-parents visual items that are marked with includeIn/excludeFrom. If I have a Group (MainGroup) with 5 children/elements that are state controlled, is there still a way to get a reference to MainGroup's children? mainGroup.numChildren and mainGroup.numElements don't work since the children are re-parented. At best, they show 1.
<s:states>
<s:State name="view1State" />
<s:State name="view2State" />
<s:State name="view3State" />
<s:State name="view4State" />
</s:states>
<s:Group id="mainGroup">
<shipping:OrderShipping id="view1"
includeIn="view1State" />
<payment:OrderPayment id="view2"
includeIn="view2State" />
<verification:OrderVerification id="view3"
includeIn="view3State" />
<confirmation:OrderConfirmation id="view4"
includeIn="view4State" />
</s:Group>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果你想让状态控制visible/includeinlayout而不是parenthood,就这样做
If you want states to control visible/includeinlayout rather than parenthood, just do it like this
我在我的一个应用程序中遇到了类似的情况,这就是我完成任务的方式。我觉得有必要这么说,虽然这很有效,但我觉得它有点老套。考虑到这一点:
作弊
。将此状态设置为默认状态(将其放在states
数组中的第一个位置。例如,
views< 的
Array
类型的新类成员/代码>。creationComplete
事件处理程序。在处理程序中填充views
并引用每个视图。例如,views = [view1, view2, view3, view4];
作弊
)状态:setCurrentState("view1State ");
毕竟,无论您的应用程序当前处于哪种状态,您的
views
数组都将引用每个视图。I have a similar situation in one of my applications and this is how I accomplished things. I feel obliged to say that, though this works I feel it is a bit hacky. With that in mind:
cheating
. Make this state the default one (put it first in yourstates
array.E.g.,
<shipping:OrderShipping id="view1" includeIn="cheating,view1State" />
Array
calledviews
.creationComplete
event handler. In the handler populdateviews
with references to each of the views. E.g.,views = [view1, view2, view3, view4];
cheating
) state:setCurrentState("view1State");
After all this your
views
array will have references to each of the views regardless of which state your application is currently in.我不确定底层状态实现是否会删除/添加子组件或更改其可见性。
如果是前者,我会尝试这样的方法:
如果是可见性问题,则执行以下操作:
我猜第一种方法是正确的方法。
[注意我在浏览器中编写了这段代码]
I'm not sure if the underlying state implementation removes / adds children to the component or changes their visibility.
If the former, I'd try something like this:
If it is a visibility issue, then do this:
I'd guess the first approach is the correct one.
[Note I wrote this code in the browser]
我得到了最佳答案!好吧,我会让你决定。只需对 states 数组进行操作...
I got the best answer! Well, I will let you decide. Just operate on the states array...