【发布时间】:2014-11-21 02:54:57
【问题描述】:
我有一组要传递给 HAML 页面的哈希值。
array = [{"name" => "a", "age" => 1}, {"name" => "b", "age" => 2}]
我想迭代并显示此信息。我试过这样做
#{locals[:array]}.each do |#{:value}|
%h2 #{:value["name"]}
但它不起作用。整个散列的值刚刚显示出来。如何迭代和显示这些元素?
在伪代码中,我想做以下事情:
for each element in array:
print element["name"] // I want to display this information in different HTML tags.
print element["age"]
更新:这是我的 HAML 文件。
!!!
%html
%head
%link{:href => "css/batchscreen.css", :rel => "stylesheet", :type => "text/css"}/
%body
.container
locals[:array].each do |element|
.story
%h2 Name: #{element['name']}
【问题讨论】: