How to use WeChat applet setData

不言
Release: 2018-06-23 17:06:50
Original
2516 people have browsed it

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'
  })
 }
})
Copy after login

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template