symfony twig动态从行动路径

问题描述 投票:0回答:1

我有一个表单,我想用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') }}");
}  

使用此代码,我收到一个错误:

变量“allRecordsActions”不存在。

javascript php symfony twig symfony-2.6
1个回答
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') }}");
}
© www.soinside.com 2019 - 2024. All rights reserved.