baidu / baidu/amis

jssdk 如何在自定义事件中使用数据映射

Open
#4,141 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
18.9k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

我在外部有个叫data的object类型的变量
我想根据输入框的值来往其中放入对应的key和值于是我写了如下配置
```
{
type: "page",
body: {
type: "container",
onEvent:{
click_button: {
actions:[
{
actionType: "custom",
script: "data[${key}] = ${value};console.log(data)"
}
]
}
},
body:[
{
type: "input-text",
name: "key",
label: "键"
},
{
type: "input-text",
name: "value",
label: "值"
},
{
type: "button",
label: "提交",
level: "primary",
onEvent:{
click: {
actions: [
{
actionType: "broadcast",
eventName: "click_button"
}
]
}
}
}
]
}
}
```

但是它报了错误
`Uncaught (in promise) SyntaxError: Unexpected token '{'`
我如何修改来修复这个错误或者如何实现我的想法

Contributor guide

No contributing guide indexed for this repository

Research direction

The reported reproduction is the page/container configuration with a custom action script using data[${key}] and ${value}. Start by tracing custom-event script interpolation and compare it with the documented action syntax; done means the configuration no longer raises the syntax error and the submitted key/value are stored as intended.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.