当前位置:网站首页>微搭低代码中实现增删改查
微搭低代码中实现增删改查
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
}
]
}, // 方法入参
});
}
总结
低码使用数据源方法本身不复杂,主要是不知道如何构造入参,本篇详细的罗列了每种方法的入参,希望给你的编程之路带来一抹亮光。
边栏推荐
- JS listens for page or element scroll events, scrolling to the bottom or top
- 7-7 digital triangle
- svg线条动画背景js特效
- Ten commandments of self-learning in machine learning
- 技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放
- It's 2022, and you still don't know what performance testing is?
- U.S. House of Representatives: digital dollar will support the U.S. dollar as the global reserve currency
- Report on operation mode and future development trend of global and Chinese propenyl isovalerate industry from 2022 to 2028
- ∞ symbol line animation canvasjs special effect
- Morris遍曆
猜你喜欢

Ethernet ARP Protocol

单调栈以及单调栈的应用

技术分享| WVP+ZLMediaKit实现摄像头GB28181推流播放

∞符号线条动画canvasjs特效

抖音实战~发布短视频流程梳理

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

Is there really something wrong with my behavior?

Hibernate learning 2 - lazy loading (delayed loading), dynamic SQL parameters, caching

教程详解|在酷雷曼系统中如何编辑设置导览功能?

Tremblement de terre réel ~ projet associé unicloud
随机推荐
Hello C (VI) -- pointer and string
MySQL problem points
SAP PA certificate for no birds, which can be tested by new peers
Fast pace? high pressure? VR panoramic Inn brings you a comfortable life
为什么生命科学企业都在陆续上云?
Eye gaze estimation using webcam
How to use stm32subeide SWV function
普通人的生活准则
Go language pointer, value reference and pointer reference
Enterprise data leakage prevention solution sharing
What exactly is Nacos
im即时通讯开发应用保活之进程防杀
创意SVG环形时钟js特效
Scala IO case
Solution of IP network broadcasting system in Middle School Campus - Design Guide for Campus Digital IP broadcasting system
7-6 laying oil well pipeline
年薪百万,7年测试经验:守在一个还算不错的赛道,慢慢积累,等风来
7-2 solving the stock buying problem
7-7 solving mode problems
canvas线条的动态效果