symfony twig动态从行动路径

时间:2017-12-29 13:09:41

标签: javascript php symfony twig symfony-2.6

我有一个表单,我想用js变量改变它的作用路径。

这是当前的工作代码:

if ($('#totalRecordsOfQuery').val() < 100) {
    $('#postbackform').attr('action', "{{ path('_getAllRecordsStudentsProgress') }}");
    $('#postbackform').submit();
    $('#postbackform').attr('action', "{{ path('xyz) }}");
}

我想要类似的东西:

var allRecordsActions = "_getAllRecordsStudentsProgress";
if ($('#totalRecordsOfQuery').val() < 100) {
    $('#postbackform').attr('action', "{{ path(allRecordsActions) }}");
    $('#postbackform').submit();
    $('#postbackform').attr('action', "{{ path('xyz') }}");
}  

使用此代码,我收到错误消息:

  

变量&#34; allRecordsActions&#34;不存在。

1 个答案:

答案 0 :(得分:0)

var allRecordsActions = "_getAllRecordsStudentsProgress";
var concatenation= '{{ path("'+ allRecordsActions +'") }}';
        if($('#totalRecordsOfQuery').val()<100){
            $('#postbackform').attr('action', concatenation);
            $('#postbackform').submit();
            $('#postbackform').attr('action', "{{ path('xyz') }}");
        } 

var allRecordsActions = "_getAllRecordsStudentsProgress";
if($('#totalRecordsOfQuery').val()<100){
    $('#postbackform').attr('action', '{{ path("'+ allRecordsActions +'") }}');
    $('#postbackform').submit();
    $('#postbackform').attr('action', "{{ path('xyz') }}");
}