Home > Mobile >  WeChat small program how to effectively change the global variable?
WeChat small program how to effectively change the global variable?

Time:11-02

How to effectively change the global variable???

Thank you, every brother please help me look very

Index. WXML code is as follows:

` ` `
Insert the code here piece





` ` `




Index. The js code below

` ` `
Insert the code here piece
Zan: function (e) {
Var zan=getApp (). GlobalData. MessageList;
for(var i=0; iIf (zan [I]. ID=='zt') {
Enclosing setData ({
State: false
})
GetApp (). GlobalData. MessageList [I] flag=false;
}
The console. The log (getApp (). GlobalData. MessageList [I] flag);
}

}
` ` `
App. Js is a array,

` ` `
Insert the code here piece
The App ({
GlobalData: {
MessageList: [{
Id: 'x001',
ID: 'pl,
Flag: true,
Good head dizzy opionion0: 'today, don't want to learn how to do',
HeadImg: '../../images/headImages head1. JPG ',
School: 'southwest petroleum university,
The userName: 'the sunrise of the music ah',
Time: '19/4/18/ready,
Content: 'running with me today? '
}, {
Id: 'x002',
ID: 'zt,
Flag: true,
Opionion0: 'tomorrow is going to play, ha, ha, ha,
HeadImg: '../../images/headImages head2. JPG ',
School: 'hainan university,
The userName: 'the sunrise of the music ah',
Time: '19/4/18/ready,
},
{
Id: 'x003',
ID: 'BZT,
Flag: true,
Opionion0: 'I want to drink water ah,
HeadImg: '../../images/headImages head3. JPG ',
School: Beijing university,
The userName: 'pig',
Time: '19/4/18/ready,
}
]
}})
` ` `

Function description: I want to realize the function of the * * is: when you click index. WXML on a page, in the index. The change in global variables in js array value of the flag, to realize the ID filtering (i.e., the same show ID and buttons, different data hiding) * *
Difficulties: * now I changed the value of the global variable flag, but click on the button, the hidden and not hide, excuse me, what should I do? *

CodePudding user response:

Var app=getApp ()
App. GlobalData. MessageList=newdata

CodePudding user response:

Dynamic global variables do not support it

CodePudding user response:

With the storage
  • Related