简体   繁体   English

条件表达式问题的灵活评估(数据绑定?)

[英]Flex valuation of conditional expression issue (data binding ?)

I'm in trouble with valuation of conditional expression in Flex . 我在Flex评估条件表达式时遇到麻烦。

Let me explain. 让我解释。

I have this : 我有这个 :

    <s:Label text="SomeTextLawyer" includeInLayout="{Session.isLawyer()}"
 visible="{Session.isLawyer()}"/>
    <s:Label text="SomeTextDoctor" includeInLayout="{Session.isDoctor()}"
 visible="{Session.isDoctor()}"/>

This Session object is defined as below : 此Session对象定义如下:

public class Session extends Singleton
{
    [Bindable]
    private static var user:User;

[...]

    public static function isDoctor():Boolean {
        return Session.user.type == model.type.DOCTOR;
    }

    public static function isLaywer():Boolean {
        return Session.user.type == model.type.LAWYER;
    }
}

I have a mechanism that change the user, so my user can be first a doctor and then a lawyer. 我拥有更改用户的机制,因此我的用户可以首先是医生,然后是律师。 Problem is that my labels keep their first valuation. 问题是我的标签保持其首次估价。 If I connect as a doctor first, I still have the doctor label displayed if I change my user as a lawyer. 如果我首先以医生身份连接,但是如果我将用户更改为律师,则仍会显示医生标签。 And vice versa... 反之亦然...

On the AS code, my user is the good kind of user, but not on my mxml files... So only the displayed part doesn't see the user switching. 在AS代码上,我的用户是很好的用户,但在我的mxml文件中却不是。。。因此,只有显示的部分看不到用户切换。

Any idea ? 任何想法 ?

Thank you in advance ! 先感谢您 !

try using a bindable boolean var to check the user type, for example : 尝试使用可绑定的布尔型var来检查用户类型,例如:

[Bindable] public var isDoctor:Boolean;
[Bindable] public var isLawyer:Boolean; 

and set their values in your show control routine, for example: 并在您的表演控制例程中设置它们的值,例如:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
               creationComplete="application1_creationCompleteHandler(event)">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

                [Bindable] public var isDoctor:Boolean;
                [Bindable] public var isLawyer:Boolean; 

            protected function application1_creationCompleteHandler(event:FlexEvent):void
            {
                isDoctor = Session.isDoctor();
                isLawyer = Session.isLawyer();
            }

        ]]>
    </fx:Script>
    <s:VGroup>
        <s:Label text="Some Text Lawyer" includeInLayout="{isLawyer}"  visible="{isLawyer}"/>
        <s:Label text="Some Text Doctor" includeInLayout="{isDoctor}"  visible="{isDoctor}"/>
    </s:VGroup>
</s:Application>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM