当前位置:网站首页>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 .
边栏推荐
- Redis series 4: sentinel (sentinel mode) with high availability
- Where is the RDS MySQL read-only instance of Alibaba cloud created
- Software architecture and design (x) -- Architecture Technology
- 小程序中的分页查询
- 五舅的思考
- 【直播预约】数据架构演进下的新挑战——上海站
- 记:数字累加动画
- 5-channel di/do relay output remote IO acquisition module Modbus tcp/ibf95
- 如何快速接入统一的认证鉴权体系
- Software architecture and design (VII) -- interactive architecture
猜你喜欢

What is the concept of game testing? What are the test methods and processes?

VM501开发套件开发版单振弦式传感器采集模块岩土工程监测

振弦采集模块测量振弦传感器的流程步骤?

如何快速接入统一的认证鉴权体系

激光测距仪非接触式地表裂缝监测仪

【Multisim仿真】LM339过零电路仿真

Using SYSTEMd to manage services

NTC, PT100 thermal resistance to 4-20mA temperature signal converter

电压转电流/电流转电压模块

Instructions for mictr01 Tester development kit (vibrating wire acquisition reader)
随机推荐
NTC,PT100热电阻转4-20mA温度信号转换器
带你来浅聊一下!单商户功能模块汇总
多功能混合信号AI采集/开关量DI/DO采集转RS485/232/MODBUS模块
2021 Yahong pen test questions
Note: numerical accumulation animation
2021 肯特面试题3
RF module wireless transceiver rf63u chip application data transmission and infrastructure network
软考 系统架构设计师 简明教程 | 软件调试
JS linked list 01
记:数字累加动画
Proportional solenoid valve control valve 4-20mA to 0-165ma/330ma signal isolation amplifier
Principle and application of low cost / small volume module rs485/232 to analog signal ibf33
JS linked list 02
Learning methods 123
NTC, PT100 thermal resistance to 4-20mA temperature signal converter
占空比开关量输出高速脉冲计数器RTUModbus模块IBF63
正大杯黑客马拉松数据解析竞赛
Using SYSTEMd to manage services
[channel attention mechanism] senet
Vm501 development kit development version single vibrating wire sensor acquisition module geotechnical engineering monitoring