tp5 layui ajax 数据表格(给每条数据给状态) JS数组查询 循环

 

<script type="text/html" id="stateTpl"> 
    {{#  if(sostatefn(d) == 1){ }}
		<a class="layui-btn layui-btn-xs layui-btn-normal" >已复制</a>
    {{#  } }} 
</script>

表格

<script>
	
    layui.use(['layer', 'form','element','jquery','table'], function(){
	var layer = layui.layer
	,form = layui.form
	,element = layui.element
	,$= layui.$
	,table=layui.table;
	
	
	var arrr  = [];
	sostatefn = function(_data){  
		var show_type = 0; 
		arrr.forEach(function(item,i){ 
			if(_data.id == item){
				show_type = 1; 
			}
		});  
		return show_type;
	};  
	
	get_arr = function(type_mold){  
		$.ajax({
		  url:'{:url("content")}',
		  type:"post",
		  data:{
			type_mold:type_mold,
			action:'ajax',
		  },
		  async:false,
		  success:function(data){ 
			arrr = data
			// arrr = [291,123,45,78]
		  },
		  error:function(){
			  show_type = 0;
		  }
		});
	}
	get_tatbl = function(type_mold){
		$("#copy_id").val(type_mold); 
		  table.render({
			elem: '#demo'
			,autoSort: false //禁用前端自动排序。注意:该参数为 layui 2.4.4 新增
			,url:"{$knowledge_url}"
			,method: 'POST'
			,where: {token: '{$knowledge_token}', id:{$id},type_mold:type_mold,u:'{$host}'}
			,page: true //开启分页
			,toolbar: true
			,toolbar: '#toolbarDemo' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
			,defaultToolbar:[] //开启筛选列、打印
			,cols: [[
					{field:'id',type:'checkbox'},
					{field:'state',title:'状态',width:80,templet: '#stateTpl'},
					{field:'title',title:'标题'},
					{field:'time',title:'复制时间',width:160},
					{fixed: 'right',title:'操作', width:90, align:'center', toolbar: '#barDemo'}
			]]
		});
		get_arr(type_mold);
	}
	get_tatbl(1);

 

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页