Flex- 变量的 3 个可能值的 3 个条件

发布于 2024-11-25 06:47:06 字数 105 浏览 4 评论 0原文

我对变量的三个可能值有三个条件。在 mxml 代码中,我想为每个实例显示不同的数据网格。 有没有比为每个可能值编写三个布尔函数,然后使用该方法返回的布尔值作为是否加载每个数据网格的参数更短的方法?

I have three conditions for three possible values for a variable. In the mxml code i would like to display a different datagrid for each instance.
Is there a shorter way than writing three boolean functions for each possible value, and then using the boolean value returned by the method as a parameter for whether each datagrid will be loaded?

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

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

发布评论

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

评论(1

伊面 2024-12-02 06:47:06

您可以直接将网格的 MXML 定义中的visible 和includeInLayout 属性绑定到布尔值或计算结果为布尔值的表达式。唯一的限制是您必须能够将评估表达为单个语句。但是,您可以使用复合条件,但您不能执行诸如存储变量然后检查它之类的操作。您可以像这样简单地完成此操作:

<mx:DataGrid visible="{myObject=='state1'}" includeInLayout="{myObject=='state1'}"/>
<mx:DataGrid visible="{myObject=='state2'}" includeInLayout="{myObject=='state2'}"/>
<mx:DataGrid visible="{myObject=='state3'}" includeInLayout="{myObject=='state3'}"/>

请注意,这仍然会导致创建所有三个网格,因为它们的父容器被创建。或者,您实际上可以使用状态来添加或删除特定网格...最终,最好的选择是创建一个网格定义并根据状态有条件地更改其属性。有很多方法可以解决这个问题,但有些方法比其他方法更好,因此请考虑在一周视频和 UIComponent 生命周期中查看 Flex,以确保您了解您的选择的含义。

另请注意,如果您需要复杂的条件,因为您使用的是 XML,则需要使用

&

对于像

<mx:DataGrid visible="{myObject=='state3'&&someOtherThing=='whatever'}" includeInLayout="{myObject=='state3'&&someOtherThing=='whatever'}"/>

上次编辑这样的每个&符号,我建议使用这个:
http://livedocs.adobe.com/flex/3 /html/help.html?content=using_states_3.html

you can directly bind the visible and includeInLayout properties within the MXML definition of the grid to either a boolean or to an expression that evaluates to a boolean. The only limitation is that you have to be able to express the evaluation as a single statement. You can however use compound conditions you just can't do something like say store a variable then check against it. You'd pull this off simply like this:

<mx:DataGrid visible="{myObject=='state1'}" includeInLayout="{myObject=='state1'}"/>
<mx:DataGrid visible="{myObject=='state2'}" includeInLayout="{myObject=='state2'}"/>
<mx:DataGrid visible="{myObject=='state3'}" includeInLayout="{myObject=='state3'}"/>

Note this will still cause all three grids to be created as a result of their parent container being created. Alternatively you can actually use states to add or remove particular grids... ultimately the best option is to create one grid definition and change the properties on it conditionally based on the state. There are many ways to solve this but some are better than others so consider looking into Flex in a week videos and UIComponent life cycle to be sure you understand the implications of your choice.

Also to note if you need a complex condition since you're in XML you'll need to use

&

for each ampersand like

<mx:DataGrid visible="{myObject=='state3'&&someOtherThing=='whatever'}" includeInLayout="{myObject=='state3'&&someOtherThing=='whatever'}"/>

Last Edit I recommend using this:
http://livedocs.adobe.com/flex/3/html/help.html?content=using_states_3.html

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