使用循环创建手风琴 - Bootstrap

时间:2016-06-17 15:00:06

标签: html twitter-bootstrap velocity

我正在尝试循环播放字段以创建手风琴。它正在获取信息并正确返回。唯一的问题是,当单击面板时,另一个打开的面板不会崩溃。任何想法如何解决这个问题?

Click Here for the resulting display

{
   "title":"Пепперони",
   "engTitle":"Pepperoni",
   "price":300,
   "description":"Сами лючщи пица слющи. Тольки щто привезли дарагой.",
   "consistOf":"E666, стальная стружка, вода (без ГМО)",
   "volumeValue":500,
   "volumeTitle":"г",
   "categoryId":38
}

2 个答案:

答案 0 :(得分:2)

你在循环之外添加了<div class="panel panel-default">,这应该在foreach中,因为它有多个面板。看看正确的Bootstrap手风琴结构:http://getbootstrap.com/javascript/#collapse-example-accordion

答案 1 :(得分:0)

您可以找到最简单的方法here

<html>
<head>
<title></title>
</head>

<div id='accordion' class='accordion'>
 <h3>Header 1 ( panel No. 0 )</h3>
  <div>
    Text about Header 1    
  </div>
 <h3>Header 2 ( panel No. 1 )</h3>
  <div>
    Text about Header 2    
  </div>
<h3>Header 3 ( panel No. 2 )</h3> 
  <div>
    Text header 3
  </div>
<h3>Header 4 ( panel No. 3 )</h3>
  <div>
    Text about Header 4.
   </div>
</div>

<script src='https://code.jquery.com/jquery-3.1.1.min.js'></script>
<script src='https://code.jquery.com/ui/1.12.1/jquery-ui.min.js'></script>
<link href='https://code.jquery.com/ui/1.12.1/themes/cupertino/jquery-ui.css' rel='stylesheet'>

<script>
$(document).ready(function() {

$( '#accordion' ).accordion({
active: false,
collapsible: true
});

})
</script>
</body>
</html>