LAYUI中表格工具监听

表格部分:

{field: 'status', title: '状态', align:'center',width: 80,templet:function(d){
		return "+getGoodStatus(d.status)[1]+">"+getGoodStatus(d.status)[0]+"";
}, sort:true}
,{align: 'centser', width: 200, title: '操作', toolbar:'#gdBar'}

JS

<script type="text/html" id="gdBar">
	<a class="layui-btn layui-btn-xs" lay-event="adopt">通过</a>
	<a class="layui-btn layui-btn-xs" lay-event="refuse">拒绝</a>	
	<a class="layui-btn layui-btn-xs" lay-event="look">查看</a>	
</script>
//操作
table.on('tool(table-data)', function(obj){
	var id = obj.data.id;
	var uid = obj.data.uid;
	console.log(obj.data);
	if(obj.event === 'adopt'){
		$.getJSON('{:url("Goods/adopt")}',{id:id,uid:uid},function(data){
				if(data.code == 200){
					layer.msg(data.msg);
					//obj.del();			//删除此条
					obj.update({status:1});	//直接改变参数,前端样式会自动渲染
				}
		});
	} else if(obj.event === 'refuse'){
		layer.open({
			type: 2
			,title: '商品拒绝理由'
			,shade: 0.8
			,skin: 'layerBtn'
			,area: ['800px', '500px']
			,fixed: false
			,maxmin: true
			,content: "{:url('Goods/refuse','','')}/id/"+id+"/uid/"+uid
		});
	} else if(obj.event === 'look'){
		layer.open({
			type: 2
			,title: '商品信息审核'
			,shade: 0.8
			,skin: 'layerBtn'
			,area: ['800px', '500px']
			,fixed: false
			,maxmin: true
		  ,btn: ['关闭']
			,yes: function(index, layero){
				layer.close(index);
			}
			,content: "{:url('Goods/article','','')}/id/"+id
		}); 
	}
});

注:表格操作后,修改前端的状态以表格后台返回的结果为参考对象。而不是表格HTML显示的结果为参考对象。obj.update({status:1});

你可能感兴趣的:(#,table)