bootstrap-table中formatter使用ajax返回数据进行回显
开发中需要实现这样一个功能:会员管理添加时的充值模板可以复选框勾选多个充值模板,这里存的数据是多个充值模板的id,但是列表需要显示这个充值模板的名称,故需要在formatter中使用ajax进行后台交互查询出这些id对应的模板名称,现对ajax返回数据绑定问题做个记录。
一、后台controller请求
/*
数据列表回显充值模板名字
*/
@PostMapping("/selectRechageSchemeNameByIds")
@ResponseBody
public R selectRechageSchemeNameByIds(String ids) {
String idArray[] = ids.split(",");
StringBuilder rechageSchemeName = new StringBuilder();
if (idArray.length > 0) {
for (String id : idArray) {
MemberRechargeScheme memberRechargeScheme = memberRechargeSchemeService.selectMemberRechargeSchemeById(Long.valueOf(id));
if (memberRechargeScheme != null) {
rechageSchemeName.append(memberRechargeScheme.getRechageSchemeName() + ",");
}
}
}
if (rechageSchemeName.length() > 0) {
rechageSchemeName.deleteCharAt(rechageSchemeName.length() - 1);
}
R r = R.success();
r.put("rechageSchemeName", rechageSchemeName);
return r;
}
二、对应列中,formatter操作
{
field: 'rechargeSchemeId',
title: '充值模板',
formatter: function (value, row, index) {
if (value.length > 0) {
var rechageSchemeName;
$.ajax({
url: prefix + "/selectRechageSchemeNameByIds", //请求后台
type: "post",
data: {"ids": value},
async: false,
success: function (data) {
if (data.code == 0) {
if (data.rechageSchemeName.length > 0) {
rechageSchemeName = data.rechageSchemeName;
}
}
}
});
return rechageSchemeName;
}
}
}
需要特别注意的有两点:
(1)、ajax请求必须设置为同步请求: async: false,异步请求返回的数据无法回显。
(2)、不可在success方法中直接返回data.rechageSchemeName,需要设置变量rechageSchemeName,给它赋值之后再返回此变量。下面这种方式数据无法回显:
{
field: 'rechargeSchemeId',
title: '充值模板',
formatter: function (value, row, index) {
if (value.length > 0) {
$.ajax({
url: prefix + "/selectRechageSchemeNameByIds", //请求后台
type: "post",
data: {"ids": value},
async: false,
success: function (data) {
if (data.code == 0) {
if (data.rechageSchemeName.length > 0) {
return data.rechageSchemeName;
}
}
}
});
}
}
}
https://blog.csdn.net/qq_34896730/article/details/102680255
相关推荐
使用bootstrap-table实现后台分页 插件资源点击此处本站下载。 引用以下css <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css" rel="external nofollow" > <link rel=...
bootstrap-table插件:bootstrap-editable,可编辑下拉框,以及代码实例,
bootstrap-table实现 行拖拽 插件 jquery.tablednd.js bootstrap-table-reorder-rows.js bootstrap-table-reorder-rows.css
[MVC]bootstrap-table表格ajax获取json数据并分页。
最近需要对表头进行冻结,找到了bootstrap-table-fixed-columns组件(也是bootstrap-table作者写的)能实现冻结效果,但带来了其他问题,包括:排序失效、列宽错位、合并行无效等,于是引入该组件的同时,顺便解决了...
基于bootstrap-table 实现 右侧列固定,也可以针对左侧列固定,针对操作列使用起来非常方便,引用jquery、bootstrap-table-fixed 样式和js文件后,可以随意设置,灵活。 fixedColumns: true,//fixedtNumber:2, //...
压缩包里面有: 1.bootstrap-table-editable.js 2.bootstrap-editable.js 3.bootstrap-editable.css 用于bootstrap table实现x-editable的行单元格编辑
bootstrap-table-export.js bootstrap-table表格导出js
压缩包里面有: 1.bootstrap-table-editable.js 2.bootstrap-editable.js 3.bootstrap-editable.css 用于bootstrap table实现x-editable的行单元格编辑
fastadmin 表格添加固定表头 bootstrap-table-fixed-columns所需插件
bootstrap-table-editable.js
bootstrap-table-zh-CN.js,有需要就下载吧
bootstrap-table-pagejump。bootstrap分页插件查询有的需要跳转到指定页面。
在原bootstrap-table-fixed-columns的基础上,解决了冻结列后,排序失效、列宽错位和合并行失效问题
支持头部列合并,并且可动态添加头部列,可支持多行title的bootstrap-table插件。 在原来的bootstrap-table中进行了改进,并增加回调函数
用于bootstrap数据表格的导出插件,在引入bootstrap其他主要js和css的前提下,再将bootstrap-table-export.js和tableExport.js引入
如有使用疑问,联系博主 bootstrap-table-fixed-columns.css固定列 冻结列
用于bootstrap数据表格的导出插件,在引入bootstrap其他主要js和css的前提下,再将bootstrap-table-export.js和tableExport.js引入。包里有两个版本的
bootstrap-table是一款基于bootstrap的table插件,相比较与easyui datagrid来说,样式更加美观,前后端分页的设计也比较有趣