amis icon indicating copy to clipboard operation
amis copied to clipboard

Form-Table-默认数据加载问题

Open icodingx opened this issue 6 years ago • 11 comments

我通过 Form 的 initApi 加载了初始数据,Table(FormItem) 该如何设置 value ?

 {
  "type": "form",
  "initApi": {
     "url": "xxx?corpId=$corpId",
     "sendOn": "corpId"
  }
  "controls": [
      {
         "type": "table",
          "label": "自建应用配置",
          **"value": "$apps",**
         "columns": [
                        {
                            "name": "agentId",
                            "label": "AgentId"
                        },
------------------------
{"msg":"操作成功",
"data":{
"corpId":"ww937153bcd346934e",
"apps":"[{\"secret\": \"xxxxxx\", \"agentId\": \"1000013\"}, {\"secret\": \"xxxxxxxxxxxxxxxxxxxxxxxx\", \"agentId\": \"1000014\"}]"},
"status":0}

icodingx avatar Jan 05 '20 05:01 icodingx

@2betop 请教了 initApi 取到的 apps 是一个数组(),form -> table 的 value 如何设置?

icodingx avatar Jan 06 '20 00:01 icodingx

有没有 ${apps | str2json} 的用法?

icodingx avatar Jan 06 '20 01:01 icodingx

你配置一下 name 为 "apps" 另外,你返回的数据看似是 string,正常应该都是后端直接解开。

2betop avatar Jan 06 '20 02:01 2betop

form -> table 的 value 如何设置?可以是 json 数组吗 ?可以添加 ${apps | str2json} 的用法吗?

icodingx avatar Jan 06 '20 02:01 icodingx

value 不支持取变量,都是 表单项的 name 关联一个变量。要做加工处理的话,要不就用接口的返回适配器,要不就是用 formula 来处理。

不过,我建议还是直接接口就返回 json 格式,而不是字符串。

2betop avatar Jan 06 '20 02:01 2betop

@2betop 请问 formula 怎么用 ?

icodingx avatar Jan 06 '20 03:01 icodingx

 "initApi": {
    "url": "/xxx",
    "adaptor": "(payload, response) => {payload.data.apps=JSON.parse(payload.data.apps); return (payload, response);}"
  },

提示: Response is empty!

icodingx avatar Jan 06 '20 04:01 icodingx

 "initApi": {
    "url": "/xxx",
    "adaptor": (payload, response) => {payload.data.apps=JSON.parse(payload.data.apps); return payload;}
  },

2betop avatar Jan 06 '20 04:01 2betop

 "initApi": {
    "url": "/xxx",
    "adaptor": (payload, response) => {payload.data.apps=JSON.parse(payload.data.apps); return payload;}
  },

提示: Response is empty!

icodingx avatar Jan 06 '20 05:01 icodingx

里面加 debugger; 语句调试一下吧,不能返回一个空的结果。

2betop avatar Jan 06 '20 05:01 2betop

能把大致 schema 贴出来吗

2betop avatar Jan 06 '20 07:01 2betop