【问题标题】:twig symfony - read jquery inside {{path()}}twig symfony - 在 {{path()}} 中读取 jquery
【发布时间】:2017-12-13 02:52:58
【问题描述】:

我有一个使用 Symfony 3 的项目

我正在尝试使用适当的参数动态生成以下 URL

http://127.0.0.1/add/{id}/{price}

我想做这样的事情(为了清楚起见,缩进了):

window.open(
    "{{ 
         path('add_family'
            , {'id': $(this).data("myid"), 
               'relation': $('#my-select').val()
         }) 
     }}"
);

这两条指令很好,给出了正确的结果

  • $(this).data("myid")
  • $('#my-select').val()

我的问题是,我怎样才能让它们在 twig 内工作,即在 {{ path() }} 函数内工作?

【问题讨论】:

    标签: php jquery symfony twig


    【解决方案1】:

    有两种方法:

    1. 从您的 twig 页面创建一个脚本并在其中设置链接。

      <script>
          var the_link = "{{path("link_name", {'id': "ID", 'relation':  "RELATION"})}}";
      
          the_link = the_link.replace("ID", $(this).data("myid"));
          //etc
      </script>
      
    2. 使用FosJsBundle

    【讨论】:

      猜你喜欢
      • 2015-02-06
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 2018-03-05
      • 2016-08-27
      • 1970-01-01
      • 2018-03-26
      • 2015-04-23
      相关资源
      最近更新 更多