我希望在Blade的{{ 大括号 }}
中拼接JavaScript变量,如下所示:
目前:
ajax: "{{ route(api.colors) }},"
我想要的是:
var page='colors';
...
ajax: "{{ route(api."+page+") }},"
这可行吗?
我希望在Blade的{{ 大括号 }}
中拼接JavaScript变量,如下所示:
目前:
ajax: "{{ route(api.colors) }},"
我想要的是:
var page='colors';
...
ajax: "{{ route(api."+page+") }},"
这可行吗?
由于花括号是在服务器端呈现且Javascript在客户端运行,因此您无法直接这样做。您可以在路线中放置占位符,然后在Javascript代码中替换此部分。就像这样:
// Imagine the `api.page` route value is `/controller/{page}`:
ajax: "{{ route(api.page) }}".replace("{page}", page);
{items}
? - Jerodev var id = $('#user_id').val();
console.log(id);
ajax: "{{ URL::to('/meme') }}/poster/"+id+"",