使用perl模板工具包时出错
我尝试使用模板工具包获取此数据,但无法获取。
$var1={
'Object'=>[
{
'Component'=>[
{
'type'=>'analog',
'name'=>'Temp',
'value'=>'23'
},
{
'type'=>'digital',
'name'=>'Temp',
'value'=>'22'
},
{
'type'=>'analog',
'name'=>'pressure',
'value'=>'23'
},
{
'type'=>'analog',
'name'=>'humidity',
'value'=>'23'
}
]
}
],
};
我尝试这样,
[% FOREACH st IN Object %]
[% FOREACH st IN Object.Component %]
[% Component.type %][% Component.name %][% Component.value %]
[% END %]
[% END %]
我无法获取这些值,而且它也没有给出任何错误,请帮助如何获取该值。
I am tried to get this data using template toolkit but I am unable to get.
$var1={
'Object'=>[
{
'Component'=>[
{
'type'=>'analog',
'name'=>'Temp',
'value'=>'23'
},
{
'type'=>'digital',
'name'=>'Temp',
'value'=>'22'
},
{
'type'=>'analog',
'name'=>'pressure',
'value'=>'23'
},
{
'type'=>'analog',
'name'=>'humidity',
'value'=>'23'
}
]
}
],
};
I tried like this
[% FOREACH st IN Object %]
[% FOREACH st IN Object.Component %]
[% Component.type %][% Component.name %][% Component.value %]
[% END %]
[% END %]
I am not able to get the values and aslo it doesn't give any error ,please help how to get this values.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的模板更改为:
Change your template to:
您有两个
st
变量。我不记得 TT 是如何处理范围的,但我怀疑这不是一件好事。您还尝试从名为Component
的变量中提取值。您尚未实例化名为“组件”的变量。请记住,如果您引用不存在的变量,正常情况下 TT 不会给出错误,它只是不输出任何内容。如果您想更改它,从而出现错误,您需要设置 STRICT 配置选项。或者,设置调试选项之一:
尝试如下操作:
You have two
st
variables. I don't remember exactly how TT handles scope but I suspect this not a good thing. You are also trying to extract values from a variable calledComponent
. You haven't instantiated a variable called component. Remember that TT under normal circumstances doesn't give you an error if you reference a variable that doesn't exist, it simply outputs nothing.If you want to change that so you get an error you need to set the STRICT configuration option. Alternatively, set one of the debug options:
Try something like: