国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

使用layui 渲染table數(shù)據(jù)表格的實(shí)例代碼

2019-11-19 13:13:01
字體:
供稿:網(wǎng)友

先上最終效果圖:

1,引入layui的css和js文件

<link rel="stylesheet" href="lib/layui/css/layui.css" rel="external nofollow" ><script src="lib/layui/layui.js"></script>

2,在頁面放置一個table元素

<table class="layui-hide" id="test" lay-filter='test3'></table>

3,通過 table.render() 方法指定該容器

layui.use('table', function(){      var table = layui.table;//      var playerName;//      if(item != undefined) {//        playerName=item;//      }      table.render({        elem: '#test' table 容器的選擇器或 DOM        ,url:'http://boss.superlychee.com/rest/web/golfTourManage/getGolfTourPlayerByTourIdAndRounds'        ,method:'post'        ,where:{tourId:tourIds,rounds:rounds,playerName:item}        ,cellMinWidth: 80 //全局定義常規(guī)單元格的最小寬度,layui 2.2.1 新增        ,cols: [[          {field:'tourPlayerId', width:80, title: 'ID1', sort: true}          ,{field:'playerName', width:80, title: '姓名'}          ,{field:'hole1', title: '1',edit: 'text'}          ,{field:'hole2', title: '2',edit: 'text'}          ,{field:'hole3', title: '3',edit: 'text'} //minWidth:局部定義當(dāng)前單元格的最小寬度,layui 2.2.1 新增          ,{field:'hole4', title: '4',edit: 'text'}          ,{field:'hole5', title: '5',edit: 'text'}          ,{field:'hole6', title: '6',edit: 'text'}          ,{field:'hole7', title: '7',edit: 'text'}          ,{field:'hole8', title: '8',edit: 'text'}          ,{field:'hole9', title: '9',edit: 'text'}          ,{field:'hole10', title: '10',edit: 'text'}          ,{field:'hole11', title: '11',edit: 'text'}          ,{field:'hole12', title: '12',edit: 'text'}          ,{field:'hole13', title: '13',edit: 'text'}          ,{field:'hole14', title: '14',edit: 'text'}          ,{field:'hole15', title: '15',edit: 'text'}          ,{field:'hole16', title: '16',edit: 'text'}          ,{field:'hole17', title: '17',edit: 'text'}          ,{field:'hole18', title: '18',edit: 'text'}          ,{field:'add', title: '操作', width:177,toolbar:"#barDemo"}        ]],      });      });

4,這個時(shí)候你的頁面差不多就是以下這個樣子了

5,正文到了,怎么把表格數(shù)據(jù)渲染進(jìn)去呢?咱們上面第三部就是渲染的一中方法,叫“方法渲染”,layui官網(wǎng)提供的三種渲染

方法,在這里不做陳述,方法渲染的優(yōu)點(diǎn)是:你可以脫離HTML文件,而專注于JS本身。尤其對于項(xiàng)目的頻繁改動及發(fā)布,其便捷性會體現(xiàn)得更為明顯,

layui的url默認(rèn)是“get”請求,我這邊是post請求,所以記得加上“method”屬性為post,

6,容易碰到的問題,按理來說這個時(shí)候應(yīng)該已經(jīng)可以看到表格數(shù)據(jù)了,為什么大多數(shù)人的表格還是渲染不出來呢?一般是因?yàn)槟忝门渲煤笈_數(shù)據(jù)格式

response: {  statusName: 'code' //數(shù)據(jù)狀態(tài)的字段名稱,默認(rèn):code  ,statusCode: 200 //成功的狀態(tài)碼,默認(rèn):0  ,msgName: 'msg' //狀態(tài)信息的字段名稱,默認(rèn):msg  ,countName: 'count' //數(shù)據(jù)總數(shù)的字段名稱,默認(rèn):count  ,dataName: 'data' //數(shù)據(jù)列表的字段名稱,默認(rèn):data}

這個時(shí)候表格一般已經(jīng)是出來了,記得,后臺提供的數(shù)據(jù)格式,和layui提供的一樣最好,這一點(diǎn)要切記,這一點(diǎn)大家可以去官網(wǎng)上看下,不做說明。

以上這篇使用layui 渲染table數(shù)據(jù)表格的實(shí)例代碼就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林網(wǎng)。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 昭觉县| 东源县| 玛沁县| 炉霍县| 永丰县| 宕昌县| 托克逊县| 桑日县| 金华市| 沙雅县| 墨竹工卡县| 保亭| 上高县| 台山市| 文昌市| 九江市| 喀喇| 南充市| 临海市| 郴州市| 蛟河市| 皋兰县| 大丰市| 清新县| 德格县| 龙州县| 台中市| 秦皇岛市| 永昌县| 延长县| 景泰县| 循化| 扎鲁特旗| 沙洋县| 临海市| 类乌齐县| 东莞市| 威远县| 绥江县| 芮城县| 江源县|