如何在Javascript Laravel Blade中编写路由URL?

这是我的路线,有2个参数,

url: '{{ route('datatable.getaccess', [$room->id_project , $room->id]) }},

如果这样写将显示:xxxxxx?xxxxxx对$ id问号 beetwen id_project,如何正确编写?因为那应该用“ /”斜杠

谢谢。

IGP

您可以将字符串占位符用于javascript。

<input type="hidden" id="_room_id" value="{{ $room->id }}">
<input type="hidden" id="_room_project_id" value="{{ $room->id_project }}">
let project_id = $('#_room_project_id').val(); // or document.getElementById('_room_project_id').value if you're not using JQuery
let id = $('#_room_id').val();                 // or document.getElementById('_room_id').value if you're not using JQuery
let url = "{{ route('datatable.getaccess', [':project_id', ':id']) }}".replace(':project_id', project_id).replace(':id', id);

这看起来是错误的,但是它有效,因为我们将字符串传递给了路由助手(后者又产生了一个字符串)

route('datatable.getaccess', [':project_id', ':id'])
// 'viewroom/:project_id/:id'

所以

let url = "{{ route('datatable.getaccess', [':project_id', ':id']) }}".replace(':project_id', project_id).replace(':id', id);

相当于

let url = "viewroom/:project_id/:id".replace(':project_id', project_id).replace(':id', id);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章