我有一个奇怪的问题,我使用simpleXML将xml字符串转换为哈希值。
但是当我尝试在子哈希或数组'属性'中循环时,它不起作用,这里是HASH:
{
"softwares" => { "type" =>"text", "multiple" =>"true" },
"edition_first_date" => { "type" =>"date" },
"edition_last_date" => { "type" =>"date" },
"documents_date_begin" => { "type" =>"date" },
"documents_date_end" => { "type" =>"date" },
"data_collection_date_begin" => { "type" =>"date" },
"data_collection_date_end" => { "type" =>"date" },
"rec_id" => { "type" =>"hidden" },
"title" => { "type" =>"text", "multiple" =>"false" },
"documents_count" => { "type" =>"hidden" },
"archive_extent" => { "type" =>"text", "multiple" =>"false" },
"archive_location" => { "type" =>"text", "multiple" =>"false" },
"access_conditions" => { "type" =>"text", "multiple" =>"true" },
"association" => {
"name" =>"distributors",
"label" =>"distributors",
"properties" => { "property" => [
{ "name" =>"person_distributors", "class_name" =>"Person" },
{ "name" =>"orgunit_distributors", "class_name" =>"Orgunit" }
] }
}
}
这是我的模板代码,当我尝试在属性中循环时,它只占用第一个属性,我不知道为什么,当我添加<%= debug v ['properties'] ['property']% >这需要所有的财产......,这很奇怪。
<% studyHash['step1'].each do |k, v|%>
<% if k == 'association' %>
<div id="<%=v['label']%>">
<h4><%=v['label']%></h4>
<a class="add-<%=v['label']%>" data-toggle="modal">add</a
<%= debug v['properties']['property']%>
<% v['properties']['property'].each do |k|%>
<%=k%>
<%=link_to_add_association(' ', f, k['name'].to_sym, :partial=>'/studies/'+k['class_name'].to_s().downcase+'_fields', :data => {"association-insertion-method" => "append" })%>
<%end%>
</div>
你能帮助我吗?
答案 0 :(得分:0)
您忘记了第8行中的结束</a>
标记:
<a class="add-<%=v['label']%>" data-toggle="modal">add</a