如何在Symfony中使用javascript变量生成路由?

如何在Symfony中使用javascript变量生成路由?,javascript,php,symfony,routes,Javascript,Php,Symfony,Routes,根据本教程,我尝试在Symfony中使用javascript路由: 这是我的密码: ... "render": function (data, type, row, meta) { return Routing.generate('get-file', { fileId: data }); } ... Amd脚本: <script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script&

根据本教程,我尝试在Symfony中使用javascript路由:

这是我的密码:

...
  "render": function (data, type, row, meta) {
  return Routing.generate('get-file', { fileId: data });

}
...
Amd脚本:

<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('get-file', { callback: 'fos.Router.setData' }) }}"></script>
<script>
const routes = require('../../public/js/fos_js_routes.json');
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';

Routing.setRoutingData(routes);
Routing.generate('rep_log_list');
</script>

const routes=require('../../public/js/fos_js_routes.json');
从“../../vendor/friendsofsymfony/jsrouting bundle/Resources/public/js/router.min.js”导入路由;
路由。设置路由数据(路由);
生成('rep_log_list');
但我得到了一个错误:

在呈现模板期间引发了异常(“某些 缺少用于生成URL的必需参数(“fileId”) 路由“获取文件”。)


这样做不需要捆绑包。
使用默认参数生成路由,然后用JavaScript变量替换它

let route = "{{ path('get-file', { filedId: 'fileId_' }) }}";
route = route.replace('fileId_', yourVariable);