我目前正在尝试在 TWIG 中使用 JQuery。我的网站是使用 Symfony2 创建的。我目前在 TWIG 中有一个表(它有效 - 见下文),我想使用 JQuery 来使我的表列可排序。
<table><tr><th>cat</th> <th>dog</th> <th>fish</th> </tr> {% for result in results %}<tr><td>{{result.cat_name}}</td><td>{% for dog in result.dogs %} {{dog.dog_name}}{% endfor %} </td> <td>{% if result.fishs is defined %} {% for fish in result.fishs %}
{{fish.fish_uri}}
{% endfor %} {% endif %} </td></tr>{% endfor %}
我想利用 DataTables(请参见此处)从我的表中获取我想要的功能。有一个捆绑包(请参阅此处)创建以允许在 TWIG 中使用 DataTables。捆绑包已成功安装 (web/bundles/uamdatatables/)。
导致我不确定的原因(因为捆绑包没有使用说明)是我试图使捆绑包工作(使我的表具有 DataTables 提供的功能),但我的表保持不变(也没有错误消息)。
想知道是否有人可以告诉我我做错了什么?我以前从未使用过 JQuery,并且是 Symfony 的新手。我需要某种“包含”语句(以获取 js 文件)吗?
//view.html.twig
<table><table id="table_id" class="display"><thead> {% block stylesheets %}
<link href="{{ asset('/bundles/uamdatatables/css/jquery.dataTables.css') }}" rel="stylesheet" />
<script type="text/javascript" charset="utf-8" src="/bundles/uamdatatables/css/jquery.dataTables.css"></script>
{% endblock %}<tr><th>cat</th> <th>dog</th> <th>fishs</th> </tr></thead> <tbody><?php $(document).ready( function () {
$('#table_id').dataTable();} );?>{% block javascripts %}
<script src="{{ asset('/bundles/uamdatatables/js/jquery.dataTables.js') }}"></script>
{% endblock %}{% for result in results %}<tr><td>{{ result.cat_name}}</td><td>{% for dog in result.dogs %}{{dog.dog_name}}{% endfor %}</td><td>{% if result.fishs is defined %} {% for fish in result.fishs %}{{fish.fish_uri}}{% endfor %}{% endif %}</td></tr>{% endfor %}</tbody> </table>
谢谢!谭雅