Flex- 变量的 3 个可能值的 3 个条件
我对变量的三个可能值有三个条件。在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以直接将网格的 MXML 定义中的visible 和includeInLayout 属性绑定到布尔值或计算结果为布尔值的表达式。唯一的限制是您必须能够将评估表达为单个语句。但是,您可以使用复合条件,但您不能执行诸如存储变量然后检查它之类的操作。您可以像这样简单地完成此操作:
请注意,这仍然会导致创建所有三个网格,因为它们的父容器被创建。或者,您实际上可以使用状态来添加或删除特定网格...最终,最好的选择是创建一个网格定义并根据状态有条件地更改其属性。有很多方法可以解决这个问题,但有些方法比其他方法更好,因此请考虑在一周视频和 UIComponent 生命周期中查看 Flex,以确保您了解您的选择的含义。
另请注意,如果您需要复杂的条件,因为您使用的是 XML,则需要使用
对于像
上次编辑这样的每个&符号,我建议使用这个:
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:
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
Last Edit I recommend using this:
http://livedocs.adobe.com/flex/3/html/help.html?content=using_states_3.html