【发布时间】:2015-10-16 20:35:19
【问题描述】:
我有一个这样的列表,例如 7141,6881,5821,8001,7904,6601,7961,6021,4721,其中每个都是员工的 ID。我有一个包含员工描述的页面,上面有一个下一步按钮。单击下一步时,我需要获取下一个员工的详细信息,如下所示。
<cfset getempls(arguments.id) />
<cfset local.emp_id_list = valueList(VARIABLES.employee.emp_id) />
<cfset emp_index = listFind(local.emp_id_list, arguments.emp_id) />
<cfset local.emp_id = "" />
<cfif emp_index LT VARIABLES.employee.recordcount>
<cfset local.emp_id = listGetAt(local.emp_id_list, emp_index + 1) />
</cfif>
我还需要在详情页抓取下3名员工的预览,也就是说,在emp_ID 7141的详情页上,我也需要显示6881,5821,8001的详情;需要遍历列表直到最后。任何人都可以提出一个最好的方法来做到这一点。我做了类似下面的事情,但即使列表中的员工少于 3 人,我也需要这样做。有什么想法吗?谢谢
<cfif listlen(local.emp_id_list) eq 3>
<cfset local.next_three_emp_id_list = listappend(local.next_3_emp_id_list, listGetAt(local.emp_id_list, emp_index + 2)) />
<cfset local.next_three_emp_id_list = listappend(local.next_three_emp_id_list, listGetAt(local.emp_id_list, emp_index + 3)) />
</cfif>
【问题讨论】:
-
使用数组更容易做到这一点。您可以利用数组索引作为偏移量。您可以使用
listToArray函数转换您的列表。 -
我很想将列表加载到数组中,然后将该数组放入会话变量中。然后我会推送当前索引,而不是整个列表
-
你能举个例子吗?
-
查询 variables.employee 中还包含什么?
标签: list coldfusion