layui table列中参数转换(1=汽车 2=火车 3=飞机) & layui table列中的值替换 (已解决)

问题: 类别属性为sort 后台数据库存的是1 2  3 但是显示的需要转换成 人才 政策  项目

代码:方法一

页面:

    <script type="text/html" id="tranSort">
    	{{# if (d.sort==1) { }}
 		  <span>人才</span>
	    {{# } else if(d.sort==2) { }}  
		  <span>政策</span>
	    {{# } else{ }}  
		  <span>项目</span>
	    {{# }}}  
    </script>

小插曲:

本想这种花括号是成对出现,伸展开更容易理解代码,万万没想到这种写法是不认识的,报错,这是因为这个模板语言不支持

js:


		cols : [ [ // 表头
		{
			field : 'check',
			title : ' ',
			fixed : 'left',
			type : 'checkbox'
		}, {
			field : 'investId',
			title : '序号',
			sort : true,
			width : 80
		}, {
			field : 'title',
			title : '标题'
		}, {
			field : 'sort',
			title : '类别',
			templet:'#tranSort'
		}
		, {
			field : 'pubdate',
			title : '发布时间'
		},{
			fixed : 'right',
			title : '操作',
			align : 'center',
			toolbar : '#barDemo',
			width : 180
		} ] ]
		,

方法二

js:

		done:function(res, curr, count){
			  console.log(res);
			  $("[data-field = 'sort']").children().each(function(){
				  
				    if($(this).text() == '1'){
				 
				      $(this).text("人才");
				 
				    }else if($(this).text() == '2'){
				 
				       $(this).text("政策");
				    }else if($(this).text() == '3'){
				 
				       $(this).text("项目");
				    }
				  })
			    //得到当前页码
			    console.log(curr); 
			    //得到数据总量
			    console.log(count);
		}

效果:

扫描二维码关注公众号,回复: 4517007 查看本文章

猜你喜欢

转载自blog.csdn.net/weixin_37020977/article/details/84571764