将 javascript 变量传递给树枝
我只想将 javascript 变量传递给树枝路径.现在我正在使用它,但它不起作用.
I just want to pass a javascript variable to a twig path. Now i'm using this, but it doesn't work.
<p id="result"></p>
<script>
var text = "";
var i;
for (varJS = 0; varJS < 5; varJS++) {
text += "<a href='{{ path('lesson',{'id': varJS }) }}'>article</a>";
}
document.getElementById("result").innerHTML = text;
</script>
推荐答案
for (varJS = 0; varJS < 5; varJS++) {
var url = '{{ path("lesson", {'id': 'article_id'}) }}';
url = url.replace("article_id", varJS);
text += '<a href='+ url +'>article</a>';
}
注意你真的应该看看 FOSJsRoutingBundle.
相关文章