条件表达式问题的弹性估值(数据绑定?)
Flex valuation of conditional expression issue (data binding ?)
我在 Flex
中对条件表达式的估值遇到了麻烦。
让我解释一下。
我有这个:
<s:Label text="SomeTextLawyer" includeInLayout="{Session.isLawyer()}"
visible="{Session.isLawyer()}"/>
<s:Label text="SomeTextDoctor" includeInLayout="{Session.isDoctor()}"
visible="{Session.isDoctor()}"/>
这个会话对象定义如下:
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;
}
}
我有一个改变用户的机制,所以我的用户可以先是医生,然后是律师。问题是我的标签保留了他们的第一个估价。如果我首先以医生身份连接,如果我将用户更改为律师,我仍然会显示医生标签。反之亦然...
在AS代码上,我的用户是好用户,但在我的mxml
文件上不是...所以只有显示部分看不到用户切换。
有什么想法吗?
提前致谢!
尝试使用可绑定的布尔变量来检查用户类型,例如:
[Bindable] public var isDoctor:Boolean;
[Bindable] public var isLawyer:Boolean;
并在您的显示控制例程中设置它们的值,例如:
<?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>
我在 Flex
中对条件表达式的估值遇到了麻烦。
让我解释一下。
我有这个:
<s:Label text="SomeTextLawyer" includeInLayout="{Session.isLawyer()}"
visible="{Session.isLawyer()}"/>
<s:Label text="SomeTextDoctor" includeInLayout="{Session.isDoctor()}"
visible="{Session.isDoctor()}"/>
这个会话对象定义如下:
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;
}
}
我有一个改变用户的机制,所以我的用户可以先是医生,然后是律师。问题是我的标签保留了他们的第一个估价。如果我首先以医生身份连接,如果我将用户更改为律师,我仍然会显示医生标签。反之亦然...
在AS代码上,我的用户是好用户,但在我的mxml
文件上不是...所以只有显示部分看不到用户切换。
有什么想法吗?
提前致谢!
尝试使用可绑定的布尔变量来检查用户类型,例如:
[Bindable] public var isDoctor:Boolean;
[Bindable] public var isLawyer:Boolean;
并在您的显示控制例程中设置它们的值,例如:
<?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>