当前位置:网站首页>JS failed to change all variables and changed to the return method. Finally, the problem was solved
JS failed to change all variables and changed to the return method. Finally, the problem was solved
2022-04-23 17:11:00 【ZHZHK001】
The first way to fail
Among them c1 c2 Is the name of a global variable
With c1 c2 Different , change Global variable with corresponding name The content of
My code below is wrong , It is impossible to change the contents of global variables , I don't know how to change it
<script type="text/javascript">
var c1 = [{
id: 1, text: ' guangdong ' }];
var c2 = [{
id: 1, text: ' guangdong ' }];
function change(){
listDict("cost","0",c1);// change c1 Global variable of // Call area
listDict("codddst","0",c2);
}
change();// Set to open the page and start immediately
// Method area
function listDict(dtype,dPid,c){
……………………………………
Layers.AjaxProxy({
…………
data: data ,
dataType: 'json',,
}).done(function (result, flag) {
if (flag) {
//
……………………………………………………
c=…………;// This will not change
}//
});
}
</script>
Later solutions
The solution is to use return Methods
Change the global variable to c1 = Method ; Add return
var c1 = [{
id: 1, text: ' guangdong '}];
var c2 = [{
id: 1, text: ' background ', pid: 1 }];
function changeSelect(){
//-----------------------------
c1 = listDict("costType","0",c1);// A key part
c2 = listDict("costType","",c2);//
}
changeSelect();// Set to open the page and start immediately
function listDict(dtype,dPid,c){
……………………………………
Layers.AjaxProxy({
cache: false ,
type: "get" ,
url: "${request.contextPath}/d4d4/dddd" ,
data: data ,
dataType: 'json',
async: false ,
}).done(function (result, flag) {
if (flag) {
//
……………………………………………………
}//
});
return c;// A key part
}
版权声明
本文为[ZHZHK001]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230553251760.html
边栏推荐
- Promise (II)
- Lock lock
- Tencent resolves the address according to the IP address
- Simulation of infrared wireless communication based on 51 single chip microcomputer
- Self use learning notes - connectingstring configuration
- Milvus 2.0 détails du système d'assurance de la qualité
- Decimal format decimal / datetime conversion processing
- STM32__ 03 - beginner timer
- Nodejs installation and environment configuration
- Solution architect's small bag - 5 types of architecture diagrams
猜你喜欢
随机推荐
Simulation of infrared wireless communication based on 51 single chip microcomputer
ASP. Net core configuration options (Part 1)
Grpc gateway based on Ocelot
Conversion between hexadecimal numbers
Lock lock
Basic case of Baidu map
Path environment variable
PHP高效读大文件处理数据
Copy constructor shallow copy and deep copy
ASP. Net core dependency injection service life cycle
SQL database
CentOS MySQL multi instance deployment
Baidu Map Case - Zoom component, map scale component
Zhimeng dedecms security setup Guide
Redis docker installation
Preliminary understanding of promse
Further study of data visualization
ASP. Net core reads the configuration file in the class library project
Use of shell sed command
Seven cattle upload pictures (foreground JS + background C API get token)

![[PROJECT] small hat takeout (8)](/img/54/0187eeb637f4dcd4ad3969b00e2b77.png)







