2017-12-29 24 views
0

Ich habe ein Formular, ich möchte seinen Weg der Aktion mit js Variable ändern.symfony Zweig dynamisch von Aktionspfad

Dies ist aktuelle Arbeitscode:

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

ich etwas will, wie:

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

Mit diesem Code, erhalte ich eine Fehlermeldung:

Variable "allRecordsActions" does not exist.

+0

der Code befindet sich in einer Zweigdatei (oder etwas, das von der TWIG-Rendering-Engine verarbeitet wird)? – Matteo

+0

ist es in Zweig Datei –

Antwort

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

oder

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

Beide nicht funktioniert, haben viele Kombination wie folgt ausprobiert, nichts funktioniert –

+1

Sie können Js Route Bundle installieren https://symfony.com/doc/current/bundles/FOSJsRoutingBundle/index.html es ist das Beste Möglichkeit, mit Routen in Javascript Symfony zu manipulieren – Zeljka