有没有办法从 json/api 响应构建 eureka 表单。到目前为止,我已经能够转换为返回到对象的 json。但在创建 for 循环来生成表单时遇到问题。
form
+++ Section("API Returns")
for values in JSONObject{
<<< TextRow() {
$0.tag = values.key
$0.title = values.name
$0.value = values.value
}
}
Run Code Online (Sandbox Code Playgroud) 我的 api 的当前响应如下:
[
{
"device_id": "1234",
"network_status": "Offline",
"status": "Yes",
"frequency": 50,
},
{
"device_id": "12345",
"network_status": "online",
"status": "no",
"frequency": 123,
},
{
"device_id": "12346",
"network_status": "online",
"status": "no",
"frequency": 423,
},
]
Run Code Online (Sandbox Code Playgroud)
使用最新文档: https://github.com/paularmstrong/normalizr/blob/master/docs/api.md#arraydefinition-schemaattribute
我知道这些文档已经更新,因此查看堆栈上的其他问题我无法找到类似的示例。“responseData”包含来自 api 的响应,它是一个对象数组。[{},{},...]
我的代码是
import { schema } from 'normalizr';
const deviceid = new schema.Entity('device_id');
const arrayOfDevices = new schema.Array({
device_id : deviceid,
})
normalize(responseData, arrayOfDevices)
Run Code Online (Sandbox Code Playgroud)
我想得到以下输出。将 device_id 作为每个对象的键的实体对象。
{
entities: {
device_id: {
'1234' : {
.....
},
'12345' : {
..... …Run Code Online (Sandbox Code Playgroud)