BootstrapTable searchList动态渲染
1. ajax动态获取数据
js中初始化表格前,ajax异步请求获得数据
1 // 动态获取类型列表 2 $.ajax({ 3 url: "shopro/user_wallet_log/getTypeList", 4 async: false, 5 success: function (res) { 6 typeList = res.data; 7 } 8 }); 9 10 // 初始化表格 11 table.bootstrapTable({
请求的路径中的代码是
1 /* \addons\shopro\model\UserWalletLog::$typeAll 2 3 public static $typeAll = [ 4 // money 5 'wallet_pay' => ['code' => 'wallet_pay', 'name' => '余额付款'], 6 'recharge' => ['code' => 'recharge', 'name' => '用户充值'], 7 'admin_recharge' => ['code' => 'admin_recharge', 'name' => '后台充值'], 8 'admin_deduct' => ['code' => 'admin_deduct', 'name' => '后台扣除'], 9 'cash' => ['code' => 'cash', 'name' => '提现'], 10 'cash_error' => ['code' => 'cash_error', 'name' => '提现驳回'], 11 'wallet_refund' => ['code' => 'wallet_refund', 'name' => '余额退款'], 12 'commission_income' => ['code' => 'commission_income', 'name' => '佣金收益'], 13 'commission_back' => ['code' => 'commission_back', 'name' => '佣金扣除'], 14 'zhuanzhang' => ['code' => 'zhuanzhang', 'name' => '转账'], 15 16 // score 17 'sign' => ['code' => 'sign', 'name' => '签到'], 18 'score_pay' => ['code' => 'score_pay', 'name' => '积分付款'], 19 'score_back_order' => ['code' => 'score_back_order', 'name' => '取消订单退回'], 20 ]; 21 */ 22 23 public function getTypeList() 24 { 25 $data = \addons\shopro\model\UserWalletLog::$typeAll; 26 $data = array_column($data, 'name', 'code'); 27 $this->success('获取类型列表成功', null, $data); 28 }
2. searchList动态渲染
{ field: 'type', title: __('Type'), searchList: typeList, formatter: Table.api.formatter.normal },