On this page
code
跳题
跳题逻辑(也称为分支或条件逻辑)允许您创建适应受访者答案的动态调查。在 rtSurvey 中,跳题逻辑通过 XLSForm 中的 relevant 列实现。
基本跳题逻辑
要实现基本跳题逻辑,请使用 relevant 列指定条件:
| type | name | label | relevant |
|----------------|---------------|-----------------------------|--------------------|
| select_one y_n | likes_pizza | 您喜欢披萨吗? | |
| select_multiple pizza_toppings | favorite_topping | 喜欢的配料 | ${likes_pizza} = 'yes' |
在此示例中,只有受访者回答"是"时,“喜欢的配料"问题才会出现。
Relevant 表达式的语法
- 使用
${ }引用其他问题变量。 - 对于
select_one题,直接比较:${question_name} = 'answer' - 对于
select_multiple题,使用selected()函数。
高级跳题逻辑
多个条件
您可以使用 and、or 和括号组合多个条件:
| type | name | label | relevant |
|---------|-------|-------------------------|-------------------------------------------|
| integer | age | 您几岁了? | |
| text | school| 您就读哪所学校? | ${age} < 18 and (${location} = 'urban' or ${location} = 'suburban') |
使用 select_multiple 题
对于 select_multiple 题,使用 selected() 函数:
| type | name | label | relevant |
|----------------|---------------|-----------------------------|-----------------------------------------|
| select_multiple pizza_toppings | favorite_topping | 喜欢的配料 | |
| text | cheese_type | 喜欢的奶酪类型 | selected(${favorite_topping}, 'cheese') |
多选中的"其他"选项
使用 relevant 实现自由文本"其他"选项:
| type | name | label | relevant |
|----------------|----------------------|-------------------------------------|---------------------------------------|
| select_multiple pizza_toppings | favorite_toppings | 您最喜欢什么披萨配料? | |
| text | favorite_toppings_other | 您还喜欢什么其他配料? | selected(${favorite_toppings}, 'other') |
记得在 choices 工作表中包含"other"选项。
rtSurvey 特有功能
动态相关性
rtSurvey 允许基于计算字段的动态相关性:
| type | name | label | calculation |
|-----------|------------|--------------------|-----------------------------|
| calculate | total_score| 总分 | ${score1} + ${score2} + ${score3} |
| text | feedback | 反馈 | ${total_score} > 75 |
重复中的相关性
rtSurvey 支持重复组内的相关性:
| type | name | label | relevant |
|--------------|--------------|------------------|------------------------|
| begin repeat | child_info | 儿童信息| |
| integer | child_age | 儿童年龄 | |
| text | school_name | 学校名称 | ${child_age} >= 5 |
| end repeat | | | |
级联相关性
rtSurvey 高效处理级联相关性,即一个问题的相关性依赖于另一个问题,而另一个问题又依赖于第三个问题:
| type | name | label | relevant |
|----------------|-------------|------------------------|------------------------|
| select_one y_n | has_car | 您有车吗? | |
| select_one car_type | car_type | 什么类型的车? | ${has_car} = 'yes' |
| text | model | 具体型号 | ${car_type} = 'sedan' |
rtSurvey 跳题逻辑最佳实践
- 保持简单:尽量避免过于复杂的相关条件。
- 全面测试:使用 rtSurvey 的预览功能测试调查中的所有可能路径。
- 考虑性能:非常复杂的跳题逻辑可能影响调查性能,尤其是在移动设备上。
- 使用清晰的变量名:这使您的相关表达式更易于阅读和维护。
- 记录逻辑:添加注释解释复杂的跳题模式,尤其是在团队协作时。
- 注意数据分析:跳过的问题将导致缺失数据。请相应规划您的分析。
跳题逻辑故障排除
- 语法错误:确保所有
${ }都正确关闭且拼写正确。 - 循环引用:避免创建问题相互依赖的循环。
- 大小写敏感:记住答案选项在相关表达式中区分大小写。
- 数值比较:对数值比较使用适当的运算符(
<、>、=)。
结论
在 rtSurvey 项目中有效使用跳题逻辑可以显著改善受访者体验和数据质量。通过利用 rtSurvey 的高级功能并遵循最佳实践,您可以创建动态、高效的调查,适应每位受访者的独特情况。
此页面有帮助吗?