【发布时间】:2015-06-26 17:15:23
【问题描述】:
我的 symfony 项目的 twig 视图中有此代码:
<table>
<thead>
<tr>
<th>DATA 1</th>
<th>DATA 2</th>
<th>DATA 3</th>
<th>DATA 4</th>
<th>DATA 5</th>
<th>DATA 6</th>
<th></th>
</tr>
</thead>
<tbody>
{% for currentData in arrayData %}
<tr>
<td>{{ currentData.data1}}</td>
<td>{{ currentData.data2}}</td>
<td>{{ currentData.data3}}</td>
<td>{{ currentData.data4}}</td>
<td>{{ currentData.data5}}</td>
<td>{{ currentData.data6}}</td>
<td>
<a><button class="btn btn-info btn-xs" id="show">Show Details</button></a> <!-- for open dialog window -->
<a href="{{ path('editData', {'idData': currentData.idData }) }}"><button class="btn btn-warning btn-xs">Edit</button></a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<!-- dialog window-->
<dialog id="window">
<div class="header">
<ul class="nav nav-tabs">
<li role="presentation" class="active">
<a>Detail</a>
</li>
<button class="btn btn-danger btn-sm pull-right" id="exit">Close</button>
</ul>
</div>
<div class="panel-body page-header">
<!-- my content here -->
</div>
</dialog>
<script>
(function() {
var dialog = document.getElementById('window');
document.getElementById('show').onclick = function() {
dialog.show();
};
document.getElementById('exit').onclick = function() {
dialog.close();
};
})();
</script>
如您所见,这是一个基本的 html 页面。我在 loop {% for currentData in arrayData %} 的表格中显示我所有的数据。
在此表上,有两种类型的按钮:Show Details 按钮和Edit 按钮。编辑按钮效果很好,没有问题,我的重定向适用于我表中的所有数据,我可以编辑我选择的数据。
对于按钮Show Details:期望的行为是在我的页面中打开一个窗口对话框,其中包含我需要为每一行显示的所有数据。但事实上,当我点击Show Details 时,我的对话框窗口只在表格的第一行工作,当我点击另一行的另一个显示详细信息按钮时,什么都没有发生(真的什么都没有)。
我哪里错了?
请注意,目前我不在窗口对话框中传递数据,而是通过 Ajax 和 Symfony 控制器来传递数据。
【问题讨论】:
标签: javascript html symfony loops twig