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

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

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

如果这样写会显示 : xxxxxx?xxxxxx,有问号 beetwen id_project 到 $id,如何正确写?因为那应该是“/”斜线

谢谢你。


子衿沉夜
浏览 99回答 1
1回答

呼唤远方

您可以为 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 JQuerylet id = $('#_room_id').val();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// or document.getElementById('_room_id').value if you're not using JQuerylet 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);
打开App,查看更多内容
随时随地看视频慕课网APP