我想用包含 JavaScript 的下拉列表显示电影的投票,但我不知道在 Twig 模板中使用 JavaScript 的正确方法是什么。我有query.dropdown.js
和modernizr.custom.63321.js
在...\PYSBundle\Resources\public\js
。在base.html.twig
我有:
(...)
<script src="js/modernizr.custom.63321.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.dropdown.js"></script>
<script type="text/javascript">
$( function()
{
$( '#cd-dropdown' ).dropdown();
});
</script>
</body>
</html>
我有哪些frontend.html.twig
延伸:base.html.twig
{% block javascripts %}
{% javascripts '@PYSBundle/Resources/public/js/jquery.dropdown.js' %}
<script src="{{ asset_url }}" type="text/javascript"></script>
{% endjavascripts %}
{% javascripts '@PYSBundle/Resources/public/js/modernizr.custom.63321.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
最后在votaciones.html.twig
fronted.html.twig`的哪个扩展中,我得到了:
<select id="cd-dropdown" class="cd-select">
<option value="-1" selected>Select a vote -</option>
<option value="1" class="one">1</option>
<option value="2" class="two">2</option>
<option value="3" class="three">3</option>
<option value="4" class="four">4</option>
<option value="5" class="five">5</option>
<option value="6" class="six">6</option>
<option value="7" class="seven">7</option>
<option value="8" class="eight">8</option>
<option value="9" class="nine">9</option>
<option value="10" class="ten">10</option>
</select>