Bootstrap Accordion Collapse not indexing divs correctly

别等时光非礼了梦想. 提交于 2019-12-25 04:19:28

问题


When trying to index divs so that the accordion buttons will collapse correctly, it's indexing every first contact in each category in my json file as 0 instead of indexing every contact no matter the category consecutively.

Here's my erb file:

<% @contacts.each do |category, hash| %>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
  <div class="panel-heading">
  <h3 class="panel-title"><%= category %></h3>
  </div>
    <div class="panel-body">
      <ul class="list-group">
        <% hash.each_with_index do |contact, index| %>
        <li class="list-group-item" style="border: none">
        <button type="button" class="btn btn-info" data-toggle="collapse" data-parent="#accordion" data-target="#collapse<%= index %>"><%= contact['name'] %><%= index %></button>
          <div id="collapse<%= index %>" class="panel-collapse collapse">
            <%= contact['email'] %></br><%= contact['ext'] %>
          </div>
        </li>
      <% end %>
      </ul>
  </div>
</div>
</div>
<% end %>

json file: (It's indexing the first name in each group i.e. "Manager, Team Lead" as 0. I want Rob = 0, Terry = 1, Ben = 3, and so on.

{
    "Manager":[
    {
      "name": "Rob",
      "email": "Rob@com",
      "ext": "ext:"
    }
  ],
  "Team Lead":[
    {
      "name": "Terry",
      "email": "Terry@com",
      "ext": "ext"
    }
    ],
  "Unix Admins":[
      {
        "name": "Ben",
        "email": "Benjamin@com",
        "ext": "ext"
      },
      {
        "name": "Prashant",
        "email": "Prashant@com",
        "ext": "ext"
      },
      {
        "name": "Harshil
        "email": "Harshil@com",
        "ext": "ext"
      },
      {
        "name": "Laxmikanth",
        "email": "Laxmikanth@com",
        "ext": "ext"
      },
      {
        "name": "Mary",
        "email": "Mary@com",
        "ext": "ext"
      }
    ],
    "On-Call Contact":[
      {
        "name": "SYSTEM ADMIN UNIX",
        "email": "Unix@com",
        "ext": "ext"
      }
    ]
}

.rb file:

get '/contact' do
    contact = Contacts.new
    @contacts = contact.getContacts
    @contacts.each { |s| puts "get /contact found contact #{s.last.first['name']}" }
    erb :contact

来源:https://stackoverflow.com/questions/38983887/bootstrap-accordion-collapse-not-indexing-divs-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!