当前位置:网站首页>How to use layui to display the data in the database in the form of tables
How to use layui to display the data in the database in the form of tables
2022-07-01 07:48:00 【Struggling young man】
layui Native table data rendering
The premise of all the following operations is that you
Must introduce layui!
One , First write html
<body>
<div class="layui-card">
<div class="layui-card-header">
<span class="layui-breadcrumb">
<a href=""> Navigation management </a>
<a><cite> View navigation </cite></a>
</span>
</div>
<div class="layui-card-body">
<form class="layui-form" action="">
<div class="layui-inline">
<button type="button" class="layui-btn layui-btn-danger" style="margin-right: 20px;"><i class="layui-icon layui-icon-delete" style="margin-right:5px;"></i> Batch deletion </button>
<div class="layui-input-inline" style="width: 200px;">
<input type="text" placeholder=" Please enter the search content " autocomplete="off" class="layui-input">
</div>
<button type="button" class="layui-btn"><i class="layui-icon layui-icon-search" style="margin-right:5px;"></i> Search for </button>
</div>
</form>
<!-- Here is the table label -->
<table class="layui-table tableRender"></table>
</div>
</div>
</body>
Be careful : The content of the table label here is empty .
Two , Introduce... Into the page js file , The content is :
layui.use(['element', 'table'], function () {
var {
element, table } = layui
table.render({
elem: '.tableRender',
url: "/admin/nav/query", // Interface for back-end data transmission
cols: [[ // Header
{
field: "nav_id", title: 'ID', width: 80, sort: true, fixed: 'left' },
{
field: 'nav_name', title: ' Navigation name ' },
{
field: 'nav_alias', title: ' Navigation alias ' },
{
field: 'nav_sort', title: ' Navigation sort ' },
{
field: 'nav_is_show', title: ' Whether to show ' },
{
field: '', title: ' operation ' },
]],
page: true
});
});
introduce
tablemodular , And deconstruct the assignment .
3、 ... and , Write back-end data interface , By querying the database , To return data
// View navigation page data
router.get("/query", (req, res) => {
const sql = "SELECT * FROM nav;"
db.query(sql, (err, results) => {
if (err) {
return res.send({
code: 1,
msg: err.msg
})
}
if (results.length) {
return res.send({
code: 0,
msg: " Data query successful ",
data: results,
count: 12, // Here is the total number of records
})
} else {
return res.send({
code: 1,
msg: " Data information query failed "
})
}
})
})
Write the interface in the corresponding route , The returned data should be in accordance with
layui The requirements ofto , See the official documents for details .Back end data interface routing uses
express.jsbuild .Used
mysql2modular , Realize database interaction . theredbIs the encapsulated module , Use by introduction , I won't go into details here .
Four , Page rendering successful


Here's just a door for everyone , Want more advanced usage , You can go to the official documents to check .
边栏推荐
- weback5基础配置详解
- 【mysql学习笔记26】视图
- Huawei modelarts training alexnet model
- 漏刻有时API接口实战开发系列(14):身份证实名鉴权验证
- ctfshow-web351(SSRF)
- iNFTnews | 从《雪崩》到百度“希壤”,元宇宙30年的16件大事
- Those high-frequency written tests and interview questions in [Jianzhi offer & Niuke 101] - linked list
- The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?
- 2022 test question bank and simulation test of tea master (primary) operation certificate
- Thesis learning -- Analysis and Research on similarity query of hydrological time series
猜你喜欢

Basic knowledge of MATLAB

Are there any practical skills for operation and maintenance management

Caesar

What information does the supplier need to know about Audi EDI project?

The H5 page has set the font thickness style, but the wechat access style in Huawei mobile phone doesn't take effect?

MySQL and redis consistency solution

软件测试方法和技术 - 基础知识概括

Custom events of components ②
![[kv260] generate chip temperature curve with xadc](/img/fc/e5e4648b09b1123b2d494b75a9f8f7.png)
[kv260] generate chip temperature curve with xadc

2022电工(中级)复训题库及答案
随机推荐
Thesis learning -- Analysis and Research on similarity query of hydrological time series
ONES 创始人王颖奇对话《财富》(中文版):中国有没有优秀的软件?
2022 tea master (intermediate) recurrent training question bank and answers
2022危险化学品经营单位主要负责人试题及模拟考试
STM32 uses esp01s to go to the cloud, mqtt FX debugging
赌上了绩效,赢了公司CTO,我要搭DevOps平台!
C # read and write customized config file
【推荐系统】美团外卖推荐场景的深度位置交互网络DPIN的突破与畅想
Mysql与Redis一致性解决方案
Atguigu---- scaffold --02- use scaffold (2)
微软宣布开源 (GODEL) 语言模型聊天机器人
[软件] phantomjs屏幕截图
Why some people earn nearly 10billion a year, while others earn 3000 a month: the details you ignore actually make the most money
redisson看门狗机制,redisson看门狗性能问题,redisson源码解析
[MySQL learning notes 28] storage function
十大劵商如何开户?另外,手机开户安全么?
How do the top ten securities firms open accounts? In addition, is it safe to open a mobile account?
软件测试方法和技术 - 基础知识概括
力扣每日一题-第31天-202.快乐数
2022 test questions and mock examinations for main principals of hazardous chemicals business units