当前位置:网站首页>Paging query in applet
Paging query in applet
2022-07-28 16:12:00 【Low code preacher】
Catalog
Daily small programs often need the function of paging query , In this article, we will explain how to realize the function of paging query in low code . Develop your own paging function , You can refer to the official method first 
Paging queries usually require input and output parameters , Page numbers are required for entering references 、 The size of each page 、 Sort field name 、 sort order 、 Query criteria .
The total number of entries should be recorded separately 、 Page number 、 The size of each page 、 Record list .
After the input and output parameters are known , Where to write the code ? Functions such as paging are generally back-end capabilities , Low code tools write back-end code in custom connectors .
Create a custom connector
Log in to the low code console , Click on Create a new custom connector 
Enter a name and identification 
Click on Create a new... Now 
Enter a name and identification , Intend to select the query list , Type selection custom code 
The part that can input code in the interface is our editor for compiling back-end logic code , You can write code directly inside .
Introduction to cloud development
We need to implement the back-end code , In fact, it should conform to the syntax of cloud development , We open the official document of cloud development , find api part 
There is a concept to understand , Namely collection. In the document database, the table of our traditional database corresponds to collection, How to find collection Well ?
We can open cloud development cloudbase, Then enter our environment , Find the database 
Each set is on the list . With a set, how to write code ? Here you can refer to the customized code section of the official wechat documentation , Copy the code into the custom code editor 
module.exports = async function (params, context) {
const result = await context.database.collection('lcap-data-1TSuH5tum-product_qnniu21-preview').get();
// Return the result of this method here , It needs to be mapped with the structure defined by the output parameter
return {
records: result.data
};
};
After the code is written, you need to do method testing , First, you need to add an input parameter , After adding, we can see the implementation results 
Pagination implementation ideas
To achieve paging , A total of several fields are required , The first is to find the total number of records , The total number of records we can use count Method to calculate
module.exports = async function (params, context) {
const result = await context.database.collection('lcap-data-1TSuH5tum-product_qnniu21-preview').get();
const total = await context.database.collection('lcap-data-1TSuH5tum-product_qnniu21-preview').count();
// Return the result of this method here , It needs to be mapped with the structure defined by the output parameter
return {
total:total.total,
records: result.data
};
};

The total number of records has , Not all the results we return every time , You need to filter the data according to the page number transmitted and the number of items displayed on each page
module.exports = async function (params, context) {
const result = await context.database.collection('lcap-data-1TSuH5tum-product_qnniu21-preview').skip(params.pageSize*(params.pageNo-1)).limit(params.pageSize).get();
const total = await context.database.collection('lcap-data-1TSuH5tum-product_qnniu21-preview').count();
// Return the result of this method here , It needs to be mapped with the structure defined by the output parameter
return {
total:total.total,
records: result.data
};
};
After everything is done, you can click the parameter mapping , To automatically map out parameters 
Use connectors
After the paging method is completed, it usually needs to be used in the application , One is that it can be used directly in variables 
The other is that it can be bound in the data list 
Why customize the paging function
The officially generated paging method can only realize single table business , In actual business, we often need to split tables , However, in the scenario of multi table query, data needs to be displayed , At this time, you must implement paging logic by yourself . In the next part, we will explain how to realize multi table paging query , Coming soon .
边栏推荐
- 射频模块无线收发RF63U芯片应用数据传输和基建网络
- Advantages of optical rain gauge over tipping bucket rain gauge
- 活动速递| Apache Doris 性能优化实战系列直播课程初公开,诚邀您来参加!
- 2021 亚鸿笔试题2
- js 双向链表 01
- Thermistor PT100, NTC to 0-10v/4-20ma converter
- 记:数字累加动画
- Rust 入门指南(rustup, cargo)
- 便携式钻孔测斜仪数据采集仪测量原理与测斜探头的连接及使用方法
- Encoder high speed pulse counter Modbus RTU module ibf150
猜你喜欢

How to measure the vibrating wire sensor by vibrating wire acquisition module?

带你来浅聊一下!单商户功能模块汇总

Pyqt5 rapid development and practice 5.1 tables and trees

2-channel Di high-speed pulse counter, 1-channel encoder to Modbus TCP wired wireless module ibf161

2路DI高速脉冲计数器1路编码器转Modbus TCP有线无线模块IBF161

光学雨量计应用降雨量检测

0-75mv/0-100mv to rs485/232 communication interface Modbus RTU acquisition module ibf8

MySQL add and delete indexes

Multifunctional mixed signal AI acquisition / switching value di/do acquisition to rs485/232/modbus module

js中的for循环总结
随机推荐
比例电磁阀控制阀4-20mA转0-165mA/330mA信号隔离放大器
记录一下 clearfix 清除浮动
How to measure the vibrating wire sensor by vibrating wire acquisition module?
记:数字累加动画
2021 Yahong pen test questions
JS priority queue
Duty cycle switch output high speed pulse counter rtumodbus module ibf63
R语言ggplot2可视化绘制线图(line plot)、使用gghighlight包突出高亮线图中满足组合判断条件的线图(satisfies both condition A and B)
2-channel Di high-speed pulse counter, 1-channel encoder to Modbus TCP wired wireless module ibf161
Record Clearfix clear float
多功能混合信号AI采集/开关量DI/DO采集转RS485/232/MODBUS模块
深部位移监测系统wk813应用边坡、大坝、堤防、铁路和建筑基坑开挖等深部位移测量
兆骑科创创新创业大赛人才引进平台,双创赛事高层次人才引进
远距离串口服务器( 适配器)UART/I2C/1-Wire/SPI PS304常见问题及注意事项
Installation points and precautions of split angle probe
Play dead prototype chain
仅需三步 轻松实现远程办公
RF module wireless transceiver rf63u chip application data transmission and infrastructure network
两种特殊函数(箭头函数和方法)
js中的for循环总结