我正在运行Coldfusion8
,并且正在努力访问我设置的数组。如何在Coldfusion中访问二维数组中的元素?
我的阵列设置是这样的:
Application.strConfig.respH = arrayNew(2);
Application.strConfig.respH[1][1] = "s";
Application.strConfig.respH[1][2] = 127;
Application.strConfig.respH[2][1] = "m";
Application.strConfig.respH[2][2] = 230;
...
造成这样的:
RESPH:
[array]
1) [array]
1) s
2) 127
2) [array]
1) m
2) 230
我需要根据大小,我得到一个页面上的默认号码。所以例如,当我结束m
我需要得到respH
值为m
。现在我试着这个:
<cfscript>
LOCAL.runner = "s,m,l,xl";
LOCAL.lt = ListGetAt(LOCAL.runner, LOCAL.i, ",");
LOCAL.height = Application.strConfig.respH[ LOCAL.lt ];
</cfscript>
这样做,Coldfusion抱怨The value m cannot be converted to a number
。
问题:
如何访问我的strConfig
对象中的元素?
感谢您的帮助!
如果您需要按特定键查找数据,请不要使用数组。使用结构。对于数组,您必须循环才能找到匹配的键。 (CF9 +支持'ArrayFind') – Leigh
Ya。我只是将它更改为像这样的对象:'Application.strConfig.respH.s = 127'来访问它,就像这样:'Application.strConfig.respH [LOCAL.lt]'。让我们看看这是否有效。你想让你的评论成为一个答案,所以我可以检查吗? – frequent