admin 发表于 2025-11-15 20:00:57

fastadmin从列表页带参数跳转到其他列表页怎么接收参数

比如我们从A列表页的列表项传参category_id进入B列表页,在A列表页实现如下代码:

{
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            align: 'right',
                            buttons: [
                              {
                                    name: 'item',
                                    text: __('项目'),
                                    title: __('查看项目'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    // icon: 'fa fa-list',
                                    url: 'tongji/items/index/category_id/{ids}',
                                    extend: 'data-area=["90%","80%"]',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
                                    }
                              }
                            ],
                            formatter: Table.api.formatter.operate
                        }

在B列表页的后端php代码的index方法中接收参数代码:
public function index()
    {
      //设置过滤方法
      $this->request->filter(['strip_tags', 'trim']);
      if (false === $this->request->isAjax()) {
            $category_id = $this->request->param('category_id');
            $this->view->assign('category_id', $category_id);
            return $this->view->fetch();
      }
      //如果发送的来源是 Selectpage,则转发到 Selectpage
      if ($this->request->request('keyField')) {
            return $this->selectpage();
      }
      [$where, $sort, $order, $offset, $limit] = $this->buildparams();
      $list = $this->model
            ->with('category')
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);
      $result = ['total' => $list->total(), 'rows' => $list->items()];
      return json($result);
    }

在B列表页的index.html中实现添加B列表项带A页面过来的参数代码:
<a href="{:url('tongji/items/add',['category_id'=>$category_id])}" class="btn btn-success btn-dialog {:$auth->check('tongji/items/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>

页: [1]
查看完整版本: fastadmin从列表页带参数跳转到其他列表页怎么接收参数