-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wxs的getDataset 读取不到标签上data-*的值 #17383
Comments
这样写亲测有效: data-index="{{index}}" 但是这个作用域之外的变量没办法这样传进去: const [state, setState] = useState(1)
// ...
<Script module="wxsModule" src="./test.wxs"></Script>
{virtualOrder.map((item, index) => (
<View
key={item.id}
data-index="{{index}}"
data-state="{{state}}" // 在 wxs 是完全读不到
onTouchStart={wxsModule.handleTouchStart}
onTouchMove={wxsModule.handleTouchMove}
>
{item.id}
</View>
))} 我发现只要是用 {} 包起来的,在逻辑层读出来是 NaN,在 wxs 则是完全读不到,即便我里面写的是常量也一样:
我也想知道如何传参进 wxs |
通过你的启发,我查看了编译之后的结果,发现这样是可以传参进去的: dataState={state} 它会编译成: data-state="{{item.dataState}}" 这样就可以在 wxs 通过 |
按照微信文档来prop(应该也可以是其他声明)就是外部定义可以传入wxs的属性。wxs中的propObserver可以监听到prop的变化 |
相关平台
微信小程序
小程序基础库: 3.7.8
使用框架: React
复现步骤
正常调用wxs中instance的getDataset会获取到index的值。
但是编译后的wxml为:
其中data-index是这样的data-index="{{item.data-index}}"。导致获取不到
期望结果
正确获取data-*的值
实际结果
实际因为编译后wxml属性设置不正确,获取不到准确值
环境信息
补充信息
上面的change:prop(属性前面带change:前缀)是在 prop 属性被设置的时候触发 WXS 函数,值必须用{{}}括起来。类似 Component 定义的 properties 里面的 observer 属性,在setData({propValue: newValue})调用之后会触发。
以上是微信小程序原话。
针对change:prop这种形式React并不支持。所以采用changeProp={xxx}形式书写,解析的wxml也不对。wxml会解析为change-prop。暂时我写了plugin对输出文件进行文本替换。请官方看下这两个问题
The text was updated successfully, but these errors were encountered: