0

你好,

我尝试在 FlashBuilder (FlexProject) 中这样做

protected function btn_detail_view_clickHandler(event:MouseEvent):void
        {
            CurrentState="Statistiques" || "PartMarche";
        }

但它不起作用,我想这不是正确的语法,但正确的语法是什么?谢谢

PS:当我单击按钮时,我想当状态等于“statistiques”或“partMarche”时,当前状态更改为详细视图;)

4

3 回答 3

1

在 ECMAScript 语言中,||是一个短路运算符,如果计算结果为“真”值,则返回左侧表达式结果,否则返回右侧表达式结果。非空字符串总是计算为真值,所以这里总是返回左边的表达式。与您的示例等效的手写代码是:

if ("Statistiques")
    CurrentState = "Statistiques";
else
    CurrentState = "PartMarche";

这种类型的短路运算符用于在某些情况下为变量设置默认值:

CurrentState = PreviousState || "Some string";

在该示例中,如果PreviousState为 null 或 false 或空字符串,CurrentState则将设置为“某些字符串”。如果PreviousState是像“其他字符串”这样的字符串,CurrentState将被设置为“其他字符串”。

于 2010-06-08T22:06:07.800 回答
1

感谢您澄清您想要做什么。要检查是什么CurrentState,您需要使用 if 条件对其进行测试:

    if (CurrentState == "Statistiques" || CurrentState == "PartMarche")
    {
        // Of course, use the actual name of your detail view here
        CurrentState = "DetailView";
    }
于 2010-06-08T22:14:45.790 回答
0

好的,事实上我需要删除该.Statistiques代码在所有州都有效

 click.Statistiques="btn_detail_view_clickHandler(event)"

对不起,我自己太快了,没有完成教程。

你的回答将阻止我问下一个问题!谢谢你 ;)

于 2010-06-08T22:17:13.573 回答