当前位置:网站首页>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
边栏推荐
- Clickhouse - data type
- Kingdee Cloud Star API calling practice
- AIOT产业技术全景结构-数字化架构设计(8)
- Read a blog, re understand closures and tidy up
- 2. Electron's HelloWorld
- Devexpress GridView add select all columns
- matlab如何绘制已知公式的曲线图,Excel怎么绘制函数曲线图像?
- Shell-cut命令的使用
- On lambda powertools typescript
- Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
猜你喜欢
ASP. Net core JWT certification
Signalr can actively send data from the server to the client
线性代数感悟之1
Deep understanding of control inversion and dependency injection
快时钟同步慢时钟域下的异步控制信号slow clk to fast clk
C语言函数详解
Nodejs reads the local JSON file through require. Unexpected token / in JSON at position appears
ClickHouse-表引擎
Smart doc + Torna generate interface document
[WPF binding 3] listview basic binding and data template binding
随机推荐
Shell-sort命令的使用
Use of shell awk command
Further optimize Baidu map data visualization
C listens for WMI events
Generate random numbers with high quality and Gaussian distribution
Use of Shell sort command
基于51单片机红外无线通讯仿真
Use between nodejs modules
Customize my_ Strcpy and library strcpy [analog implementation of string related functions]
Node access to Alipay open platform sandbox to achieve payment function
Grpc gateway based on Ocelot
Detailed explanation of the penetration of network security in the shooting range
Document operation II (5000 word summary)
AIOT产业技术全景结构-数字化架构设计(8)
JSON deserialize anonymous array / object
Baidu Map Case - modify map style
Feign report 400 processing
Milvus 2.0 质量保障系统详解
Rtklib 2.4.3 source code Notes
New keyword learning and summary