setData()无法赋值,为什么用wx:for页面不渲染?

小程序 文章 2022-01-27 16:00 615 0 全屏看文

AI助手支持GPT4.0

setData()无法赋值,为什么用wx:for页面不渲染?setData() cannot be assigned, why is the page not rendered with wx:for?

setData()无法赋值,为什么用wx:for页面不渲染?

调用函数获取到的数组,通过setData赋值,页面上通过wx:for渲染。但是查到的数据未渲染。

初始化赋值:

控制台能打印全部的数据,但是也很奇怪。

但是页面上只能显示初始赋值的数据,没有调用方法获得的新数据

部分代码

The array obtained by calling the function is assigned by SetData, and the page is rendered by Wx: for. However, the data found was not rendered. Initialization assignment: the console can print all the data, but it's also strange. However, only the data of the initial assignment can be displayed on the page, and there is no code for the new data obtained by calling the method

回答:

brave:

异步。。。

dreamhunter:

需要用setData https://developers.weixin.qq.com/miniprogram/deveference/api/Page.html#%E7%BB%84%E4%BB%B6%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86%E5%87%BD%E6%95%B0

  1. 直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致


拾忆:

JS异步问题

-EOF-

AI助手支持GPT4.0