zoukankan      html  css  js  c++  java
  • Fastadmin 后台表单,外键关键,步骤

    1.在 publicassetsjsackend 目录中找到对应的js,修改

    2.对应控制器中加上index()方法;开启关联查询

    重点:

    protected $relationSearch = true; //开启关联查询

    public function index()
    {

    //设置过滤方法
    $this->request->filter(['strip_tags']);
    //当前是否为关联查询
    $this->relationSearch = true; // 解决排序问题
    if ($this->request->isAjax()) {
    //如果发送的来源是Selectpage,则转发到Selectpage
    if ($this->request->request('keyField')) {
    return $this->selectpage();
    }
    list($where, $sort, $order, $offset, $limit) = $this->buildparams();
    $total = $this->model
    ->with(['choice'])
    ->where($where)
    ->order($sort, $order)
    ->count();

    $list = $this->model
    ->with(['choice'])
    ->where($where)
    ->order($sort, $order)
    ->limit($offset, $limit)
    ->select();

    $list = collection($list)->toArray();
    $result = array("total" => $total, "rows" => $list);

    return json($result);
    }
    return $this->view->fetch();
    }

    3.对应模型中model 中加上关联的方法

    public function choice()
    {
    return $this->belongsTo('Choices', 'dw_id', 'id', [], 'LEFT')->setEagerlyType(0);   // Choices ------- 需要关联的模型  ;  dw_id ----- 外键id ; id ------ 关联表的id
    }

    4. 最终效果图

    5.最后还有些小问题,为什么做了以上的步骤之后,只显示字段名,最后一步,同步语言包,把需要用的语言同步即可

    详细文档,可查

    https://doc.fastadmin.net/docs/controller.html#关联查询-5
  • 相关阅读:
    LinQ&EF任我行(一)LinQ to SQL (转)
    WPF数据模板和控件模板
    Sql优化
    SQL锁表语句
    js动态创建dom
    js实现等待n秒后按钮可用
    js关于事件冒泡
    工作流学习(个人总结)
    sql常用函数
    将Datatable序列化为Json对象返回到客户端
  • 原文地址:https://www.cnblogs.com/roseY/p/9810397.html
Copyright © 2011-2022 走看看