fastadmin动态渲染统计信息

很多时候我们需要在页面额外显示服务端传回的动态数据,此时我们只需要在index.html视图中添加:

html 复制代码
<a href="javascript:;" class="btn btn-default" style="font-size:14px;color:dodgerblue;">
    <i class="fa fa-dollar"></i>
    <span class="extend">
        金额:<span id="money">0</span>
        单价:<span id="price">0</span>
    </span>
</a>

找到对应的js文件,添加对应的事件:

javascript 复制代码
  index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'kehu/index' + location.search,
                    add_url: 'kehu/add',
                    edit_url: 'kehu/edit',
                    del_url: 'kehu/del',
                    multi_url: 'kehu/multi',
                    import_url: 'kehu/import',
                    table: 'kehu',
                }
            });

            var table = $("#table");

            table.on('load-success.bs.table', function (e, data) {
                //这里可以获取从服务端获取的JSON数据
                console.log(data);
                //这里我们手动设置底部的值
                $("#money").text(data.extend.money);
                $("#price").text(data.extend.price);
            });

下面的controller部分的内容:

重写index方法

注意:默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法destroy/restore/recyclebin三个回收站方法

* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑

* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改

php 复制代码
   public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if (false === $this->request->isAjax()) {
            return $this->view->fetch();
        }
        //如果发送的来源是 Selectpage,则转发到 Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        $list = $this->model
            ->where($where)
            ->order($sort, $order)
            ->paginate($limit);
        $result = ['total' => $list->total(), 'rows' => $list->items(),"extend" => ['money' => 1024, 'price' => 888]];
        return json($result);
    }

这样就能实现对应的效果:

相关推荐
AI成长日志2 小时前
【实用工具教程】Linux常用命令速查与实战场景:文件操作、进程管理与网络调试高频命令解析
linux·php
该怎么办呢2 小时前
Source/Core/Matrix4.js
前端·javascript
小江的记录本2 小时前
【MyBatis-Plus】Spring Boot + MyBatis-Plus 进行各种数据库操作(附完整 CRUD 项目代码示例)
java·前端·数据库·spring boot·后端·sql·mybatis
傻啦嘿哟2 小时前
Python 操作 Excel 条件格式指南
开发语言·python·excel
逆境不可逃2 小时前
LeetCode 热题 100 之 33. 搜索旋转排序数组 153. 寻找旋转排序数组中的最小值 4. 寻找两个正序数组的中位数
java·开发语言·数据结构·算法·leetcode·职场和发展
星空下的月光影子2 小时前
易语言开发从入门到精通:进阶篇·数据处理与分析自动化·高频刚需手工转自动场景全覆盖
开发语言
林夕sama2 小时前
多线程基础(四)
java·开发语言
Yang-Never2 小时前
ADB ->adb shell perfetto 抓取 trace 指令
android·开发语言·adb·android studio
ccchen8882 小时前
适配帝国CMS 8.0:全新帝国CMS免登录采集发布插件
经验分享·爬虫·php·帝国cms自动采集发布插件·帝国cms8.0·帝国cms自动采集插件·帝国cms采集发布模块