Conditional logic is a system of rules you can use to specify when an interaction you've built should occur in the web browser. For example, you can stipulate that a button click will advance users to the next page in your prototype only if they have filled in all required fields in a form.条件逻辑是一个规则系统,可用于指定何时在浏览器中触发已构建的交互。例如,你可以规定,仅当用户在表单中填写了所有必填字段时,单击按钮才能将用户推进到下一页。
Think of conditions as having an if/then relationship with their interactions: if the condition is met, then the interaction will be executed.将条件视为与它们的交互具有“如果/则”关系:如果条件满足,则将执行交互。
You can create everything from simple conditions that affect only a single interaction to complex branching logic that controls every area of a prototype.你可以创建从仅影响单个交互的简单条件到控制原型每个区域的复杂分支逻辑。
Building Conditions创建条件
To add conditional logic to an interaction, hover over the event name and click Enable Cases. In the Condition Builder dialog that appears, click Add Logic.要将条件逻辑添加到交互中,请将鼠标悬停在事件名称上,然后单击“启用案例”。在出现的“条件生成器”对话框中,单击“添加逻辑”。
In the Condition Builder, you can configure one or more conditional statements using the fields in each row. A conditional statement compares two values in some way to produce a true or false result:在“条件生成器”,你可以每一行的字段配置一个或多个条件语句。条件语句以某种方式比较两个值产生对或错的结果:
One value — How it compares to — A second value
For example, you can verify that a text field has been filled in with a particular value with the following condition:例如,你可以通过以下条件验证文本是否已经填充特定的值。
text on widget — Text Field — equals — text — your value here
This conditional statement evaluates to true when the target text field's entered text equals the value provided in the rightmost field.当目标文本字段的输入文本等于右边字段中提供的值时,此条件语句的执行结果为ture。
Satisfying "All" or "Any" Conditional Statements满足“全部”或“任何”条件语句
When you set up multiple conditional statements for a case, you can decide whether the case gets executed when all the statements evaluate to true or when just any one statement evaluates to true. You can control this in the dropdown at the top-right of the Condition Builder.当一个案例设置多个条件语句时,你可以决定是否在所有语句都为ture或仅一个语句为ture时执行该案例。你可以在“条件生成器”右上方的下拉列表中控制此设置。 |
Events With Multiple Conditional Cases (IF and ELSE)具有多个条件案例的事件
When an event has multiple cases under it, you can use conditional logic to determine which of them will be executed in the web browser. You do this by building IF / ELSE chains.当事件下有多个案例时,你可以使用条件逻辑来确定将在Web浏览器中执行的事件。你可以通过构建IF/ELSE链来实现。
IF / ELSE chains are made up of conditional cases whose conditions depend on one another. Each condition in the chain will only be evaluated if the previous condition "fails" by evaluating to false. Once a condition "passes" by evaluating to true, the prototype will stop evaluating further conditions in the chain.IF/ELSE链由条件情况构成,条件之间相互依赖。仅当先前条件反馈为false而失败时,才会执行链中每个条件。一旦条件反馈为ture而通过,原型将停止执行链中的其他条件。
For example, the submit button for a login form might have two conditional Click or Tap cases that do different things depending on whether or not the user has provided valid login credentials.例如,登录表单的提交按钮具有两个条件的点击案例,他们根据用户是否提供了有效的登录凭证而执行不同的操作。
If the Email and Password fields both contain the correct values when the button is clicked, the first condition will evaluate to true and its case will be executed, opening the Account Dashboard page. The second case will not be evaluated at all.当点击按钮时,电子邮件和密码字段均包含正确值,第一个条件返回ture并执行第一个案例,打开账户仪表盘页面。第二种情况完全不会执行。 If, however, one of the two fields doesn't contain the correct value when the button is clicked, the first condition will evaluate to false and its case will not be executed. The prototype will then move on to the second case and evaluate its condition. The second case has no condition, so it gets executed by default, and the error message is displayed.但是,如果当点击按钮时两个输入框只要有一个不包含正确的值,第一个条件返回false且第一个案例不执行。 然后原型将移至第二种情况并执行其条件。 第二种情况没有条件,因此默认情况下将执行它,并显示错误消息。 |
Tip提示
Placing an ELSE IF true case (one with no condition) at the end of an IF / ELSE chain is a common way to create a catch-all or "default" case that will always be executed when all other conditions in the chain above it fail. Don't put any other ELSE cases after it, though — their conditions will never be evaluated since the ELSE IF true case evaluates to true automatically.在IF / ELSE链的末尾放置ELSE IF ture(无条件)是创建一个“此外”或“默认”案例的一种常见方式,该条件将在其上链中的所有其他条件失败时执行。 但是,请勿在其后放置任何其他ELSE案例,因为ELSE IF true案例会自动执行为true,所以永远不会执行条件。
The example above is fairly simple, but you can add as many ELSE cases to a chain as you like. For instance, the Click or Tap event above could include another ELSE case, above the one for the error message, that opens an administrator user profile when you log in to an admin account. The error message would only be displayed if incorrect credentials were entered for both the admin and non-admin accounts.上面的示例非常简单,但是你可以根据需要向链中添加任意多个ELSE案例。 例如,上面的点击事件可能包括另一种ELSE情况,在该错误消息的情况下,当你登录到管理员帐户时打开管理员用户资料。 仅当为管理员和非管理员帐户输入都错误时,才会显示错误消息。
Creating Multiple IF / ELSE Chains创建多个IF / ELSE链
By default, the first conditional case under an event is the IF case, and all following cases are ELSE cases in the IF / ELSE chain. You can create additional IF / ELSE chains by changing ELSE cases into IF cases. To do so, right-click a case name and select Toggle IF / ELSE.默认情况下,事件下的第一个条件情况是IF情况,随后的所有情况都是IF / ELSE链中的ELSE情况。 你可以通过将ELSE案例更改为IF案例来创建其他IF / ELSE链。 为此,请右键单击案例名称,然后选择“切换IF / ELSE”。
IF cases' conditions are always evaluated in the web browser, and each IF case starts its own IF / ELSE chain. Create multiple chains when you want to evaluate multiple conditional criteria independently of one another.IF案例的条件总是在Web浏览器中评执行,并且每个IF案例都将启动其自己的IF / ELSE链。 当你要彼此独立地评估多个条件时,请创建多个链。
For example, the submit button for a signup form might have two IF / ELSE chains under its Click or Tap event, one that that determines whether the user has opted to sign up for a newsletter and a second determines whether the user has filled in all required fields.例如,注册表单的“提交”按钮在其点击事件下可能具有两个IF / ELSE链,一个确定用户是否选择了订阅新闻通讯,另一个确定用户是否填写了所有必填字段。
If the Newsletter Checkbox is checked when the submit button is clicked, the first case's condition will evaluate to true, and the NewsletterVar variable's value will be set to "true."如果单击“提交”按钮时选中了“新闻通讯”复选框,则第一种情况的条件将评估为true,并且NewsletterVar变量的值将设置为“ true”。 The second case's condition will then be evaluated regardless of the outcome of the first case. If the user has filled in both text fields, the condition will evaluate to true, and the user will be directed to the Account Setup page. The third case's condition will not be evaluated because it is an ELSE case in the second case's IF / ELSE chain.然后,无论第一个案例的结果如何,都将执行第二个案例的条件。 如果用户同时填写了两个文本字段,则条件将执行为true,并将用户定向到“帐户设置”页面。 将不执行第三种情况的条件,因为它是第二种情况的IF / ELSE链中的ELSE情况。 However, if one or both of the text fields is blank, the second case's condition will fail, and the prototype will move on to the third case, which shows an error message.但是,如果一个或两个文本输入框为空白,则第二种情况的条件将失败,并且原型将移至第三种情况,这将显示一条错误消息。 |