怎么获取layui表格某个单元格的值
layui.use('table', function(){
var table = layui.table;
table.render({
elem: '#test'
,url:'http://localhost:8081/CollegeBBS/Shop'
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可
title: '提示'
,layEvent: 'LAYTABLE_TIPS'
,icon: 'layui-icon-tips'
}]
,id: 'gid'
,title: '商品表'
,cols: [[
{type: 'checkbox', fixed: 'left'}
,{field:'gid', title:'ID', width:80, fixed: 'left', unresize: true, sort: true}
,{field:'goods_name', title:'商品名', width:150, edit: 'text'}
,{field:'goods_num', title:'数量', width:120, edit: 'text', sort: true}
,{field:'goods_price', title:'价格', width:180}
,{field:'goods_pic', title:'图片', width:200, sort: true}
,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:250}
]]
,page: true
});
//头工具栏事件
table.on('toolbar(test)', function(obj){
var checkStatus = table.checkStatus(obj.config.id);
switch(obj.event){
case 'getCheckData':
var data = checkStatus.data;
layer.alert(JSON.stringify(data));
break;
case 'getCheckLength':
var data = checkStatus.data;
layer.msg('选中了:'+ data.length + ' 个');
break;
case 'isAll':
layer.msg(checkStatus.isAll ? '全选': '未全选');
break;
//自定义头工具栏右侧图标 - 提示
case 'LAYTABLE_TIPS':
layer.alert('这是工具栏右侧自定义的一个图标按钮');
break;
};
});
//监听行工具事件
table.on('tool(test)', function(obj){
var data = obj.data;
var checkStatus = table.checkStatus('gid');
var i=checkStatus.id;
console.log(checkStatus.data);
console.log(i);
//console.log(obj)
if(obj.event === 'buy'){
$.ajax({
type:"post", // doGet方法当中 post:doPost
url:"http://localhost:8081/CollegeBBS/Shop",
data:{"checkStatus.data":checkStatus.data}, //所要提叫的数据
success:function(da){ //数据从后面的servlet往前台传
console.log(da);
$("#points").append(da.data[1].ponits);
}
});
}
});
});