weixin_33720078 2019-09-02 11:42 采纳率: 0%
浏览 37

在Select2输出中为groupBy

I'm using Select2 for dynamic drop-down search with Ajax, same "type" (column name) is not grouping.

type

Tried to group similar column using groupBy() but its retrieving only first row.

sametype

As you can see above it's fetching all data perfectly but not grouping.

Controller:

 $data = DB::table('vehitrans')
                ->select("id", "name", "type")
                ->where('name', 'LIKE', "%$search%")->orWhere('type','LIKE', "%$search%")
                ->groupBy('type')
                ->get();

Ajax:

 processResults: function (data) {
            return {
              results:  $.map(data, function (item) {
                    return {
                        text: item.type,
                        children: [{
                         text: item.name,
                         id:item.id,
                        }]
                    }
                })
            }
          }

I want all "name" should come under its respective "type" eg.

Vehicles
   Car
   Tractor
  • 写回答

0条回答 默认 最新

    报告相同问题?