fastadmin 主键不是ID时,toggle无法执行的解决方法

Table.api.formatter.toggle默认使用的是id作为主键,假如这个表格的主键不是id,绑定的数据会变为undefined,从而导致执行失败。

打开assets/js/require-table.js文件
找到下列代码,并修改(注释2行,新增1行):

复制代码
toggle: function (value, row, index) {
                    //var table = this.table;//注释掉
                    //var options = table ? table.bootstrapTable('getOptions') : {};//注释掉
                    var options = $(table).bootstrapTable("getOptions"); //新增这行
var pk = options.pk || "id"; var color = typeof this.color !== 'undefined' ? this.color : 'success'; var yes = typeof this.yes !== 'undefined' ? this.yes : 1; var no = typeof this.no !== 'undefined' ? this.no : 0; var url = typeof this.url !== 'undefined' ? this.url : ''; var confirm = ''; var disable = false; if (typeof this.confirm !== "undefined") { confirm = typeof this.confirm === "function" ? this.confirm.call(this, value, row, index) : this.confirm; } if (typeof this.disable !== "undefined") { disable = typeof this.disable === "function" ? this.disable.call(this, value, row, index) : this.disable; }

            return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Click to toggle') + "' class='btn-change " + (disable ? 'btn disabled no-padding' : '') + "' data-index='" + index + "' data-id='" + row[pk] + "' " + (url ? "data-url='" + url + "'" : "") + (confirm ? "data-confirm='" + confirm + "'" : "") + " data-params='" + this.field + "=" + (value == yes ? no : yes) + "'><i class='fa fa-toggle-on text-success text-" + color + " " + (value == yes ? '' : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>"; },
复制代码

 

posted @   zhang_you_wu  阅读(210)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
历史上的今天:
2023-01-04 UniPush FCM 需要的Legancy server key官方已经停用了
2023-01-04 uniapp修改APP为正式版
2023-01-04 uniapp 华为离线推送
2022-01-04 git error:invalid path问题解决
点击右上角即可分享
微信分享提示