无法修改变量
实现场景:
通过点击按钮,修改全局变量,在页面显示变量数据。
存在的问题:
希望可以修改“data”里的参数
当前方案:
通过“变量赋值”里的“页面参数”修改“data”里的参数,但是找不到参数,这个里面的参数是可以在哪里命名。
{
"type": "page",
"title": "自定义页面",
"regions": [
"body"
],
"body": [
{
"type": "button",
"label": "修改变量",
"onEvent": {
"click": {
"actions": []
}
},
"id": "u:1cf96e49c8ca"
},
{
"type": "tpl",
"tpl": "${test}",
"inline": true,
"wrapperComponent": "",
"id": "u:3c1ed8cfcdb8",
"themeCss": {
"baseControlClassName": {
"padding-and-margin:default": {
"marginLeft": "20px"
}
}
}
}
],
"id": "u:000913866c8b",
"data": {
"rootUrl": "",
"test": "111"
}
}
@asister 请按照 issue 的格式模版修改下 issue 的内容,并提供一下 amis schema
@asister 请按照 issue 的格式模版修改下
issue的内容,并提供一下amis schema
我想问下,事件里的“变量赋值”中“页面参数”,是需要在哪里命名才能进行修改。 “data”里的参数只能用“setValue”方法进行修改么。 我们现在的问题就是不知道该怎么修改全局变量。
@asister
{
"type": "page",
"data": {
"test": "initial-name"
},
"body": [
{
"type": "service",
"data": {
"newData": {
"test": "new-name"
}
},
"body": [
{
"type": "button",
"label": "更新",
"level": "primary",
"className": "mt-2 mb-2",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "top_page",
"args": {
"value": "${newData}"
}
}
]
}
},
"id": "u:81d73b5462f3"
}
],
"id": "u:12c24f8fb50e",
"dsType": "api"
},
{
"type": "tpl",
"tpl": "${test}",
"inline": true,
"wrapperComponent": "",
"id": "tpl_data",
"themeCss": {
"baseControlClassName": {
"padding-and-margin:default": {
"marginLeft": "20px"
}
}
}
}
],
"id": "top_page",
"asideResizor": false,
"pullRefresh": {
"disabled": true
}
}
不知道上面的 schema 能不能满足你的诉求
@asister 尝试回答一下你的提问
-
页面参数这个东西不知道你说的是什么,是指actionType是link或者url时 ,params这个参数吗?如果你指的是setValue的变量要从哪里定义的话,在数据链上能取到就好了吧 - 部分组件的某些交互或行为会对当前组件的数据域进行更新,如果是跨数据域更新的话,还是需要用
setValue吧,通过 节点id来设置目标数据域组件就好了
{
"type": "page",
"id": "top_page",
"data": {
"test1": "initial-name1",
"test2": "initial-name2"
},
"body": [
{
"type": "service",
"body": [
{
"type": "button",
"id": "u:81d73b5462f3",
"label": "更新",
"level": "primary",
"className": "mt-2 mb-2",
"onEvent": {
"click": {
"actions": [
{
"actionType": "setValue",
"componentId": "top_page",
"args": {
"value": {
"test1": "111111",
"test2": "222222"
}
}
}
]
}
}
}
],
"id": "u:12c24f8fb50e",
"data": {
"newData": {
"test": "new-name"
}
},
"dsType": "api"
},
{
"type": "tpl",
"tpl": "${test1}",
"id": "u:54e82febe96e"
},
{
"type": "tpl",
"tpl": "${test2}",
"themeCss": {
"baseControlClassName": {
"padding-and-margin:default": {
"marginLeft": "var(--sizes-base-8)"
}
}
},
"id": "u:4fce7021d3bb"
}
],
"asideResizor": false,
"pullRefresh": {
"disabled": true
}
}
Amis低代码前端框架交流群【QQ1群】:717791727 Amis低代码前端框架交流群【QQ2群】:721182449
结论是不要在“变量赋值”选页面,要在“组件特效动作”里面选页面,这交互多多少少有点只有写代码的人自己知道是怎么用的了
好的