Home > Article > WeChat Applet > How to use WeChat applet setData
This article mainly introduces the relevant information on the detailed explanation of the use method of the WeChat applet setData. Friends in need can refer to the following
The detailed explanation of the use method of the WeChat applet setData
I recently encountered the following problems when using setData of the WeChat applet. As follows:
The official website document uses setData() to set the attributes of an element of the array object. This is how it is used:
Page({ data: { array: [{text: 'init data'}], }, changeItemInArray: function() { this.setData({ 'array[0].text':'changed data' }) } })
Values like 'array[0].text' : 'changed data' are used. But in actual use, our setting of an element in the array is dynamic. That is, we should usually be 'array[' index '].text' : 'changed data' , where index should be a dynamic number. But obviously, this cannot be used in the key of the object.
So, I can only use a workaround. As follows:
var param = {}; var string = "array["+index+"].text; param[string] = 'changed data'; that.setData(param);
That is, prepare the object in advance.
I hope there will be a better way in the future.
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
How to use the WeChat applet date and time picker
##
The above is the detailed content of How to use WeChat applet setData. For more information, please follow other related articles on the PHP Chinese website!