moy
是基於模型框架 kero
和 UI
框架 neoui
實現的應用框架,是前端集成解決方案,爲企業級應用開發而生。
github地址:https://github.com/iuap-design/tinper-moyjavascript
添加grid表格ui:進入pages/cardtable/cardtable.html
中加入grid表格相關代碼到相應位置:html
<div class="list-panel" id="manager"> <h2>系統管理</h2> <!-- grid表格相關代碼 begin --> <div class="main-container cartable-container"> <div class="hr-table"> <div u-meta='{"id":"gridcardtable","type":"grid","data":"dt1","columnWidth":"150px","multiSelect":true,"contentSelect":false,"contentFocus":false,"canSwap":false}'> <div options='{"field":"code","title":"系統編碼","dataType":"String","editType":"string"}'></div> <div options='{"field":"name","title":"系統名稱","dataType":"String","editType":"string"}'></div> <div options='{"field":"gateway","title":"網關地址","dataType":"String","editType":"string"}'></div> <div options='{"field":"radiodatacontroller","title":"須要受權","type":"u-checkbox","data":"dt1","editOptions":{"datasource":"radiodatacontroller"},"renderType":"comboRender"}'></div> <div options='{"field":"radiodataassociate","title":"用戶自關聯","type":"u-checkbox","data":"dt1","editOptions":{"datasource":"radiodataassociate"},"renderType":"comboRender"}'></div> <div options='{"field":"combodatamodel","title":"認證模式","dataType":"String","editType":"string","renderType":"comboRender","editOptions":{"datasource":"combodatamodel"}}'></div> <div options='{"field":"operate","dataType":"String","title":"操做","renderType":"optFun","editable":false,"autoExpand":true}'></div> </div> </div> <!-- 分頁部分 --> <div id='pagination' class='pagination u-pagination pagination-sm'></div> </div> <!-- grid表格相關代碼 end --> </div>
在js中添加grid表格中每一列對應field的參數:進入pages/cardtable/cardtablemeta.js
中,將下面代碼直接拷貝到該文件中前端
var metaCardTable={ meta: { //系統名稱,和html中每一列的options參數中的field是一一對應 "name":{ type:'string', required:true, notipFlag: true, hasSuccess: true, nullMsg:'系統名稱不能爲空!' }, "code":{ type:'string', required:true, notipFlag: true, hasSuccess: true, nullMsg:'系統編碼不能爲空!' }, "radiodatacontroller":"", "radiodataassociate":"", "combodatamodel":"", "gateway": "", "operate": "" } };
而後將上面的js文件引入到pages/cardtable/cardtablemeta.js
中,而且在init()中加入如下代碼來實現html和數據的綁定:java
var listUrl = ctx + '/cardtable/list'; var viewModel = { app: {}, draw: 1,//當前頁面index totlePage: 0, pageSize: 5, totleCount: 0, //dt1對應的就是上面html中的u-meta的data中的dt1 dt1: new u.DataTable(metaCardTable), radiodatacontroller: [{ value: 'Y', name: '是' }, { value: 'N', name: '否' }], radiodataassociate: [{ value: 'Y', name: '是' }, { value: 'N', name: '否' }], combodatamodel: [{ name: '信任', value: 'Y' }, { name: '不信任', value: 'N' }], event: { //清除datatable數據 clearDt: function(dt) { dt.removeAllRows(); dt.clear(); }, // 卡片表數據讀取 initCardTableList: function() { var jsonData = { pageIndex: viewModel.draw - 1, pageSize: viewModel.pageSize, sortField: "createtime", sortDirection: "asc" }; $.ajax({ type: 'get', url: listUrl, dataType: 'json', data: jsonData, contentType: 'application/json;charset=utf-8', success: function(res) { if (res) { if (res.success == 'success') { if (res.detailMsg.data) { if(jsonData.pageSize==5&&jsonData.pageIndex==1){ res.detailMsg.data.content.splice(0,5); }else if(jsonData.pageSize==5){ res.detailMsg.data.content.splice(5,3); } viewModel.totleCount = res.detailMsg.data.totalElements; viewModel.totlePage = res.detailMsg.data.totalPages; //更新分頁信息 viewModel.event.comps.update({ totalPages: viewModel.totlePage, pageSize: viewModel.pageSize, currentPage: viewModel.draw, totalCount: viewModel.totleCount }); viewModel.dt1.removeAllRows(); viewModel.dt1.clear(); viewModel.dt1.setSimpleData(res.detailMsg.data.content, { unSelect: true }); } } else { var msg = ""; if (res.success == 'fail_global') { msg = res.message; } else { for (var key in res.detailMsg) { msg += res.detailMsg[key] + "<br/>"; } } u.messageDialog({ msg: msg, title: '請求錯誤', btnText: '肯定' }); } } else { u.messageDialog({ msg: '後臺返回數據格式有誤,請聯繫管理員', title: '數據錯誤', btnText: '肯定' }); } }, error: function(er) { u.messageDialog({ msg: '請求超時', title: '請求錯誤', btnText: '肯定' }); } }); }, //分頁相關 pageChange: function() { viewModel.event.comps.on('pageChange', function(pageIndex) { viewModel.draw = pageIndex + 1; viewModel.event.initCardTableList(); }); }, sizeChange: function() { viewModel.event.comps.on('sizeChange', function(arg) { viewModel.pageSize = parseInt(arg); viewModel.draw = 1; viewModel.event.initCardTableList(); }); }, //頁面初始化 pageInit: function() { viewModel.app = u.createApp({ el: element, model: viewModel }); //找到分頁的節點 var paginationDiv = $(element).find('#pagination')[0]; //初始化分頁頁面,在獲取到頁面的具體的數據時候還會去更新分頁信息 this.comps = new u.pagination({ el: paginationDiv, jumppage: true }); this.initCardTableList(); viewModel.event.pageChange(); viewModel.event.sizeChange(); } } } $(element).html(html); viewModel.event.pageInit();
而後刷新頁面,看到表格出現了!git
在此代碼中,主要最重要的就是u-meta中的json字符串其中的參數,我這裏控制的是不能點擊,表頭不支持拖動更改列順序,其餘功能能夠參見文檔github
到這裏,咱們已經完成了前面的準備工做,後面我會開始寫如何去實現實現grid數據新增ajax
請期待下一篇。json
(完)app