求助:表格无法重载问题

提问 已结
9 133
赋予东流兮
悬赏:20飞吻
版本:layui 2.4.5 浏览器:
如下图所示,执行搜索ID 后 表格无法重载QAQ

json文件是自己本地写的,刚入门,求大神帮忙



---------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="css/layui.css"/>
</head>
<body>


<div class="search-box">

<div class="layui-inline">
<input class="layui-input" name="id" id="input" autocomplete="off">
</div>
<div class="layui-btn" data-type="reload" id="search">搜索</div>
</div>
</form>
<div class="layui-col-lg12">

<table id="table" class="layui-hide"></table>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script src="layui.js"></script>
<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
layui.use(['form','element','table'], function(){
var form = layui.form;
var element = layui.Element;
var table = layui.table;
var tableObj = table.render({});
form.on('submit(form)', function(data){
var result = data.field
console.log(result);
return false;
});
//删除
table.on('tool(table)',function(obj){
var data = obj.data;
// console.log(obj)

});
//方法渲染表格
table.render({
elem: '#table'
,url:'json/data.json'
,cols: [[
{checkbox: true}
,{field:'id', title: 'ID',sort: true}
,{field:'title', title: '标题',sort: true}
,{field:'type',sort: true, title: '类型', sort: true,edit:true}
,{field:'content',sort: true, title: '内容'}
,{field:'time',sort: true, title: '发布时间'}
,{title:'操作', toolbar: '#barDemo', }
]]
,id:'reloadtable'
,page: true
,height: 500
});

var $ = layui.$;
$("#search").on('click',function(){
var keyword = $("#input").val()
table.reload('reloadtable',{
page: {
curr:1
}
,where: {
id:keyword
}
});
});

});
</script>
</body>
</html>
回帖