如何在 ColdFusion 中循环结构数组
我有这个结构数组设置:
<cfset table_columns = [
{name="Right Name", var_name="right_name", searchable="true", sortable="true"},
{name="Right Type", var_name="right_type", searchable="true", sortable="true"},
{name="Right Description", var_name="right_descr", searchable="true", sortable="true"},
{name="Edit", var_name = "editcol", searchable="false", sortable="false"}
]>
我将如何循环它?这是我需要做的一个例子(这显然不起作用):
<cfloop array="#table_columns#" index="data_index">
{"sName": "#table_columns[data_index]['name']#", "sTitle": "#table_columns[data_index]['var_name']#", "bsearchable": "#table_columns[data_index]['searchable']#", "bsortable": "#table_columns[data_index]['sortable']#"},
</cfloop>
I have this array of structures setup:
<cfset table_columns = [
{name="Right Name", var_name="right_name", searchable="true", sortable="true"},
{name="Right Type", var_name="right_type", searchable="true", sortable="true"},
{name="Right Description", var_name="right_descr", searchable="true", sortable="true"},
{name="Edit", var_name = "editcol", searchable="false", sortable="false"}
]>
How would I loop through that? Here is an example of what I need to do (which is obviously not working):
<cfloop array="#table_columns#" index="data_index">
{"sName": "#table_columns[data_index]['name']#", "sTitle": "#table_columns[data_index]['var_name']#", "bsearchable": "#table_columns[data_index]['searchable']#", "bsortable": "#table_columns[data_index]['sortable']#"},
</cfloop>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于数组循环,
index
值是数组的元素,而不是位置。含义data_index
是一个结构。因此,您可以像往常一样输出键(使用结构或点表示法)。With an array loop, the
index
value is an element of the array, not a position. Meaningdata_index
is a structure. So you can output the keys as usual (with either structure or dot notation).这是从 CF 文档中获取的近似值:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-71a6.html
我从来没有这样做过,但希望这能让你开始。
This is an approximation taken from the CF docs:
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-71a6.html
I've never had to do it, but hopefully that'll get you started.