尝试获取视图并将其放入数组容器中。我使用了这段代码,但遗憾的是没有工作:
$data['list'] = User::get();
return response()->json(['view' => view('table-data', $data), 'count'=>10]);
//output is:
{"view":{},"count":10}
//view is null
我想获取视图并呈现为$('tbody')。html(view); 感谢
答案 0 :(得分:1)
有两种方法可以返回视图
1)返回视图
Syntax :return view('view_name', ['var_name' => 'value']);
Example : return view('table-data',['count'=>10]);
2)使用紧凑功能返回视图
Syntax : return view('view_name', compact('var1','var2','var3'));
Example : return view('table-data',compact('count'));
答案 1 :(得分:0)
已经使用 view() - > render()解决了它:
return response()->json(['view' => view('table-data', $data)->render(), 'count'=>10]);