Comments (5)
每一个api请求都可以使用对象类型配置,像这样:
api: {
method: 'get',
url: '/api/xxx',
data:{
x: 'xxx'
},
// 这里可以配置请求接收适配器
adaptor: (payload, response) => {
let data = payload.data;
// ...对data进行一些normalize操作
return {
...payload,
data
}
},
// 这里配置发送适配器
requestAdaptor:(api)=>{
// 这里可以在请求前对api进行改写
return {
...api,
data:{
...api.data,
other: 'somedata' // 加点其他数据
}
}
}
}
但是请注意,处理后的数据结构要遵循amis的规范才可以正常工作
例如crud的结构是:
{
status:0,
msg:'xxx',
data:{
items:[], // 这里列表数据
count: 10,
page: 1,
pageSize: 10
...其他
}
}
from amis.
@RickCole21 谢谢解答,不过有个问题是,配置文件是JSON格式的,从JSON解析到对象的过程中,类似于adaptor这层函数类型的配置是怎么处理的呢?
from amis.
- 配置如果使用 json 文件来配置的话,不支持 function,所以这种情况只能用 js 来配置 json
- 如果一定要用json,只能在统一的入口 fetcher 那一层,做适配了,根据 api 地址不同,写不同的适配逻辑。
from amis.
- 配置如果使用 json 文件来配置的话,不支持 function,所以这种情况只能用 js 来配置 json
- 如果一定要用json,只能在统一的入口 fetcher 那一层,做适配了,根据 api 地址不同,写不同的适配逻辑。
我的想法是这样,要进一步提高生产效率的话还是需要做一套可视化编辑器处理配置文件,那么配置文件选择json入库存储应该是比较合适的选择,但管理系统对接的api结构不统一,normailize这一层又比较频繁,这种场景下的解决方案只有在统一入口的fetcher做适配吗?
from amis.
嗯,目前平台做了个适配器配置的东西,就是走统一的 fetcher 那的钩子
from amis.
Related Issues (20)
- 在custom动作中toast无法正确显示提示内容 HOT 1
- 如何将localstorage中的数据拿出来并将其添加在header中 HOT 1
- picker 中 tree的层级超过两层且存在某个节点的 "children": null时,当选中了该节点,编辑状态下 该节点显示 undefined
- 在富文本编辑器tinymce中插入表格页面会卡死 HOT 1
- 编辑器问题,发送Psot方式Json格式数据无法正确发送 HOT 3
- 采用receiver文件上传后表单自动退出 HOT 2
- input-tree 组件的添加选项事件中,${event.data.items}为undefined HOT 1
- 为控件选择图标时有bug,配置图标麻烦且耗时 HOT 6
- amis-admin与amis-editor就不能融为一个项目吗?
- 如何在表单高级设置中发送适配器校验表单参数内容
- bytes 过滤器支持指定保留几位小数
- button icon 支持表达式
- 表格行字段内容通过表单提交后跟表头无法对齐的问题
- 最新版的crud使用card模式时,itemAction会失效
- 数据映射种【json】的参数说明有误 HOT 2
- 如何在编辑器右侧配置面板中重新调起组件配置脚手架进行二次更改配置
- iFrame组件可以去掉打开页面时的loading吗
- 富文本编辑的高度能否自适应窗口高度
- page组件initApi还没请求,list组件的source先请求了,但list组建需要page初始请求的参数,导致请求没参数
- picker组件deferApi属性功能异常,报错Uncaught (in promise) Error: deferApi is required HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from amis.