2017-12-29 24 views
0

私はフォームを持っています、私はjs変数を使ってアクションパスを変更したいと思います。symfony twigアクションパスからの動的

これは、現在の作業コードです:私は何かしたい

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') }}"); 
} 

を、私はエラーを取得しています:

Variable "allRecordsActions" does not exist.

+0

コードはtwigファイル(またはTWIGレンダリングエンジンで処理されたもの)の内部にありますか? – Matteo

+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') }}"); 
} 
+0

両方とも動作していません、このような多くの組み合わせを試しましたが、何も動作しません –

+1

jsルートバンドルをインストールすることができますhttps://symfony.com/doc/current/bundles/FOSJsRoutingBundle/index.htmlその最高javascriptで経路を操作する方法Symfony – Zeljka

関連する問題