amis icon indicating copy to clipboard operation
amis copied to clipboard

ls命令中支持变量解析吗?

Open tanjiancheng opened this issue 1 year ago • 6 comments

请问下${ls:xxxxxlocalStrorageKey.xxxx}的这种使用方法,可以支持变量解析吗?比如${ls:xxxxxlocalStrorageKey.${bizKey}},其中bizKey是存在于当前数据域的变量名,如果不支持,我还有其他方式去动态获取这个值吗?

tanjiancheng avatar Aug 22 '24 06:08 tanjiancheng

试试这个 {ls:xxxxxlocalStrorageKey[bizKey]}

2betop avatar Aug 22 '24 08:08 2betop

试试这个 {ls:xxxxxlocalStrorageKey[bizKey]} 我试了好像不行,以下是我的测试语句 { "type": "page", "data": { "bizKey": "test" }, "body": [ { "type": "tpl", "tpl": "${ls:[bizKey]}" } ] }

我如果${ls:test}这样是ok的,其中localStroage是这样的 image

tanjiancheng avatar Aug 26 '24 08:08 tanjiancheng

请问下这块目前是什么情况了?

tanjiancheng avatar Sep 19 '24 10:09 tanjiancheng

把你需要的读取的 object 数据,用 JSON.stringify 存到一个固定 key 里,然后取的时候可以从固定的这个 key 存的 object 里支持变量取。

// 存固定值 key
localStorage.setItem("a", JSON.stringify({b: 1}))
{
  "type": "page",
  "title": "标题",
  "data": {
    "cachKey": "b"
  },
  "body": "${ls:a|pick:${cachKey}}"
}

预览图

image

jinmingpang avatar Sep 25 '24 16:09 jinmingpang

感谢上面的回答,你这种属于另外一种间接方式去获取不同变量的数据,并不是我所描述的直接根据上下文变量传递来动态获取的方式

tanjiancheng avatar Sep 30 '24 07:09 tanjiancheng

是的,看你取舍吧。我们在用amis时候,也是各种取舍。

jinmingpang avatar Oct 03 '24 04:10 jinmingpang