当前位置:网站首页>微搭低代码中实现增删改查
微搭低代码中实现增删改查
2022-06-24 19:48:00 【低代码布道师】
日常教学中,经常会有人问,这个平台方法该如何使用,参数该如何传递。我们本篇就讲解一下微搭低代码中的增删改查方法该如何使用。
数据源的方法
你建立数据源之后,平台会自动生成对应的方法。
模型方法分别有新增、新增多条、删除、删除多条、更新、更新多条、查询、查询列表。
要想使用这些平台方法必须了解每个方法的入参和出参。所谓的入参是你在调用的时候必须传入的参数,所谓出参就是调用之后返回的结果。
新增方法
一般新增我们就需要传递数据源的字段,比如我这个年级数据源只有一个字段,年级名称,那你调用的时候就需要传入年级名称这个字段。
一般数据模型的方法有两种方式调用,一种是在组件中调用,一种是在低代码编辑器中调用。
新增我们一般是结合表单容器使用,比如添加一个表单容器,可以选择新增场景,设置数据源。这里的新增场景就是指调用新增方法。
这样你在文本框中输入值之后就会保存到数据源中。
第二种方式是在低码编辑器里调用,如下代码
export default async function({
event, data}) {
const result = await app.cloud.callModel({
name:'nj_popsnzw',
methodName:'wedaCreate',
params:{
njmc : '一年级'
}
})
}

方法定义好之后可以通过给按钮定义点击事件来调用
除了写代码的方式,我们还可以直接调用平台方法,传参即可
新手学习的时候主要卡在了参数如何传递,其实就和我们在代码中传递的params是一样的,只不过是通过可视化的方式传参,记得这里要用表达式进行绑定
新增多条
新增多条可以一次性的批量添加,注意我们的入参是一个数组
我们的表单容器里没有新增多条这个场景,所以必须使用代码的方式调用
export default async function ({
event, data }) {
const result = await app.cloud.callModel({
name: 'nj_popsnzw',
methodName: 'wedaBatchCreate',
params: {
records: [
{
njmc: '批量一年级' },
{
njmc: '批量二年级' },
{
njmc: '批量三年级' }
]
}
})
}
有的同学可能会说,你这个是啥我怎么看不懂。因为入参肯定是一个对象,这里的records就是方法的入参,类型是数组,但是为啥数组里边又是多个对象呢?这个其实可以看一下云开发的文档,光看微搭是搞不定的。
删除
删除只能通过低码方法调用,代码如下
export default async function({
event, data}) {
const result = await app.cloud.callModel({
name:'nj_popsnzw',
methodName:'wedaDelete',
params:{
_id : '058dfefe62b50cb70a3d3053309efc79'
}
})
}
删除多条
export default async function ({
event, data }) {
const result = await app.cloud.callModel({
name: 'nj_popsnzw',
methodName: 'wedaBatchDelete',
params: {
where: [
{
key: 'njmc',
rel: 'eq',
val: '批量一年级'
}
]
}
})
}
更新
更新的话既支持组件调用,也支持低码调用。组件调用使用表单容器即可
更新的话必须传入一个数据标识才可以。代码调用也是一样同样需要传入数据标识
export default async function ({
event, data }) {
const result = await app.cloud.callModel({
name: 'nj_popsnzw',
methodName: 'wedaUpdate',
params: {
_id:'6d85a2b962b50bb60c5c73ad0271a82e',
njmc: '一年级11'
}
})
}
更新多条
export default async function ({
event, data }) {
const result = await app.cloud.callModel({
name: 'nj_popsnzw',
methodName: 'wedaBatchUpdate',
params: {
record: {
njmc: '批量更新'
},
where: [
{
key: 'njmc', rel: 'eq', val: '一年级' }
]
}
})
}
查询
export default async function ({
event, data }) {
const result = await app.cloud.callModel({
name: 'nj_popsnzw',
methodName: 'wedaGetItem',
params: {
_id: '0ab5303b62b412680acbf05573660730'
}
})
console.log(result)
}
查询列表
查询列表可以在变量中使用、在组件中使用、在低码中使用。以下是低码使用的方法
export default async function ({
event, data }) {
const result = await app.cloud.callModel({
name: 'user_h4la7ee',
methodName: 'wedaGetRecords',
params: {
"where": [
{
"key": "openid",
"rel": "eq",
"val": app.dataset.state.openid
}
]
}, // 方法入参
});
}
总结
低码使用数据源方法本身不复杂,主要是不知道如何构造入参,本篇详细的罗列了每种方法的入参,希望给你的编程之路带来一抹亮光。
边栏推荐
- 【Proteus仿真】定时器0作为16位计数器使用示例
- Annual salary of millions, 7 years of testing experience: stay at a fairly good track, accumulate slowly, wait for the wind to come
- 为什么越来越多的实体商铺用VR全景?优势有哪些?
- 人体改造 VS 数字化身
- 浅析大型IM即时通讯系统开发难度
- Is there really something wrong with my behavior?
- 【图数据库性能和场景测试利器LDBC SNB】系列一:数据生成器简介 & 应用于GES服务
- Analysis report on production and marketing demand and investment forecast of China's boron nitride industry from 2022 to 2028
- Stm32f030f4 reading infrared remote control data
- ∞符号线条动画canvasjs特效
猜你喜欢

JPA learning 1 - overview, JPA, JPA core annotations, JPA core objects

im即时通讯开发应用保活之进程防杀

Tiktok practice ~ upload and release app video

What exactly is Nacos

Hydropower project construction scheme based on 3D GIS Development

JPA learning 2 - core annotation, annotation addition, deletion, modification and query, list query result return type, one to many, many to one, many to many

节奏快?压力大?VR全景客栈带你体验安逸生活

QT cannot be edited with UTF-8

Tiktok actual combat ~ sorting out the short video release process

Morris traversal
随机推荐
Simple use of libnum Library (hexadecimal string conversion)
Go shopping
Global and Chinese 3-Chlorobenzaldehyde industry operation mode and future development trend report 2022 ~ 2028
Tape SVG animation JS effect
Is there really something wrong with my behavior?
Scala IO reads data from URLs and other data sources
走近Harvest Moon:Moonbeam DeFi狂欢会
Leetcode topic [array] -39- combined sum
VR全景制作的优势是什么?为什么能得到青睐?
技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
Arbitrary file download of file operation vulnerability (7)
Analysis report on the "fourteenth five year plan" and development trend of China's engineering project management industry from 2022 to 2028
Report on operation mode and future development trend of global and Chinese propenyl isovalerate industry from 2022 to 2028
抖音实战~项目关联UniCloud
Investment analysis and prospect forecast report of global and Chinese propargyl chloride industry from 2022 to 2028
Tiktok practice ~ project associated unicloud
One way 和two way ANOVA分析的区别是啥,以及如何使用SPSS或者prism进行统计分析
Morris遍历
7-5 maximal submatrix sum problem
使用网络摄像头进行眼睛注视估计