用标签属性方式设置字段formatter时,发现没有效果:
如:<th data-field="sex" data-formatter="format_sex">性别</th>
原因:
bootstrap-table.js第399行,代码中只判断了formatter typeof 为function的情况
解决办法:
修改第399行代码块:
修改前
if (typeof that.header.formatters[j] === 'function') {
value = that.header.formatters[j](value, item);
}
修改后:
if (typeof that.header.formatters[j] === 'function') {
value = that.header.formatters[j](value, item);
}else if(typeof that.header.formatters[j] === 'string') {
if(typeof window[that.header.formatters[j]] === 'function') {
value = window[that.header.formatters[j]](value, item);
}
}
本文探讨了在使用bootstrap-table.js时遇到的设置字段formatter无效的问题,并提供了具体的解决办法,通过修改代码实现正确应用自定义formatter。

310

被折叠的 条评论
为什么被折叠?



