【发布时间】:2014-03-10 20:29:24
【问题描述】:
我有一个奇怪的问题,我使用 simpleXML 将一个 xml 字符串转换为哈希。
但是当我尝试在子哈希或数组“属性”中循环时,它不起作用,这里是哈希:
{
"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" }
] }
}
}
这是我的模板代码,当我尝试循环属性时,它只使用第一个属性,我不知道为什么,当我添加 它占用了所有的财产......,这很奇怪。
<% 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>
你能帮帮我吗?
【问题讨论】: