控制器
public function index() { $this->relationSearch = true; $list = $this->model ->with("category") ->field('home_articles.*,category.name as category_id') ->where($where) ->paginate($limit); } public function searchlist() { $categoryList = collection(CategoryModel::where(['status'=>'normal'])->select())->toArray(); Tree::instance()->init($categoryList); $searchlist = []; $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0)); foreach ($result as $k => $v) { $searchlist[] = ['id' => $v['id'], 'name' => $v['name']]; } return json($searchlist); }
模型
public function category() { return $this->belongsTo('Category', 'category_id')->setEagerlyType(0); }
js
{field: 'category_id', title: __('Category_id'),searchList:$.getJSON("home_articles/searchlist")},