table.reload() 不清空搜索条件是因为默认复用缓存的 where 参数;必须显式传 where: {} 才能真正清空,且需同步清 UI 和重载表格。
table.reload() 为什么不清空搜索条件
因为 table.reload() 默认复用表格实例内部缓存的 where 参数,它只刷新数据和分页,不重置请求上下文。你点“重置”按钮后调 table.reload('usertable'),接口收到的仍是上次搜索的 keyword=xxx&status=1。
必须显式传 where: {} 才真正清空
空对象 {} 是唯一能切断 where 继承链的写法;where: null、where: undefined、甚至 where: { keyword: '' } 都会把空字符串或旧引用带进请求。
- 正确:
layui.table.reload('userTable', { where: {}, page: { curr: 1 } }) - 错误:
table.reload('userTable', { where: null })(仍继承旧值) - 错误:
table.reload('userTable', { where: { status: $('#status').val() } })(绕过 form 状态,取 DOM 值不可靠)
清空 UI 和清空 where 必须同步做
只清 where,搜索框文字还在;只清 input,table.reload() 仍发旧参数。两者脱节会导致用户困惑:“我明明点了重置,怎么还搜出老结果?”
- 先清表单 UI:
layui.form.val('searchForm', {})+layui.form.render() - 再清日期组件:
laydateIns?.setValue('')(需提前保存实例) - 最后 reload:
table.reload('userTable', { where: {}, page: { curr: 1 } })
级联下拉和动态生成的清除图标要特别处理
级联 select 不是简单设 val('') 就行;清除图标点击后若没触发 change,form.val() 读不到空值——这两类场景最容易漏掉事件同步。
- 级联项清空:用
form.val('searchForm', { province: '', city: '', district: '' })+form.render('select') - 清除图标点击后:必须
$input.val('').trigger('change'),不能只改.value - 动态搜索框(如弹窗内):用
$(document).on('click', '.layui-icon-clear', ...)避免绑定丢失
where 缓存没被显式覆盖,哪怕 DOM 清得再干净,后端收到的仍是上一次的完整搜索条件。


















