动态遍历结构的数组 [英] Looping dynamically over array of structs
问题描述
我在运行结构和IM尝试将数据动态获取到屏幕上的一个购物车阵。
I have a shopping cart array of structs running and im trying to dynamically get the data to the screen.
<cfoutput>
<cfloop from="1" to="#ArrayLen(session.shoppingcart)#" index="idx">
<cfloop collection="#session.shoppingcart[idx]#" item="key">
<cfset mydata = session.shoppingcart[idx][key] >
#key# #mydata# #session.shoppingcart[idx][key]#
</cfloop>
</cfloop>
</cfoutput>
当我设置了MYDATA变量,我能够简单地套用#MYDATA#页面,并显示。
When I set the mydata variable, i am able to simply apply #mydata# to the page and it displays.
当我尝试申请#session.shoppingcart [IDX] [关键]#
页面我得到一个错误,指出它不能作为一个简单的值显示这一点。
When i try to apply #session.shoppingcart[idx][key]#
to the page i get an error stating that it cannot display this as a simple value.
这是如何得到这些信息在屏幕上显示任何想法?
Any ideas on how to get this information to display on screen ?
在此先感谢
推荐答案
听起来像是 session.shoppingcart [IDX] [关键]
是某种类型的对象。您可以使用&LT; cfdump VAR =#session.shoppingcart [IDX] [关键]#&GT;
看到该对象的键和值。
Sounds like session.shoppingcart[idx][key]
is an object of some sort. You can use <cfdump var="#session.shoppingcart[idx][key]#">
to see the keys and values in that object.
这篇关于动态遍历结构的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!