我控制器中的代码
public function see($users_parent_id)
{
$data['data'] = Downline::where('users_parent_id',$users_parent_id)->first();
$data['data2'] = Downline::where('users_parent_id',$users_parent_id)->get();
$data['data3'] = Downline::where('users_parent_id',$data['data']->users_id)->get();
$data['users'] = User::where('role','member')->get();
return view('backend.pages.downline.show', $data);
}
和我在jstree中的循环数据
<script>
$(function() {
var arrayCollection = [
{"id": "{{ $data->users_parent_id }}", "parent": "#", "text": "{{ $data->users_parent->fullname }}"},
@foreach($data2 as $item2)
{"id": "{{ $item2->users_id }}", "parent": "{{ $data->users_parent_id }}", "text": "{{ $item2->users->fullname }}"},
@endforeach
@foreach($data3 as $item3)
{"id": "{{ $item3->users_id }}", "parent": "{{ $item3->users_parent_id }}", "text": "{{ $item3->users->fullname }}"},
@endforeach
];
$('#container').jstree({
'core': {
'data': arrayCollection
}
});
});
我的问题: 如何在不使用大量foreach的情况下在jstree中循环laravel数据?
答案 0 :(得分:0)
您可以使用if let cgcontext = UIGraphicsGetCurrentContext() {
cgcontext.strokeEllipse(in: CGRect(x: center.x-diameter/2, y: center.y-diameter/2, width: diameter, height: diameter))
}
创建关联数组,然后使用laravel辅助函数array_map
将其传递给视图。