There is a problem in writing js, that is to say, I assign values to an object through the value of the loop in the for loop value, but the printed results of each assignment will be the last assigned value, and then I started the debugger, and found that there is no problem with my debug execution, but if I don't debug, all assignments will be the last one worth the problem. This is my code
var poster_name = this.More_Temp_count['posterity_name']
var city = this.More_Temp_count['city']
var blackwidow_task = this.More_Temp_count['blackwidow_task']
var redis_key = blackwidow_task['redis_key']
var task_id = blackwidow_task['task_id']
var key_test = blackwidow_task['blackwidow_output']['db_config_test']['key']
var key_db = blackwidow_task['blackwidow_output']['db_config']['key']
this.loading = true
for (var x in city_list){
// Construct request parameters
console.log('1')
console.log(city_list[x])
// Reassign every cycle
var More_Temp_count_copy = this.More_Temp_count
More_Temp_count_copy['city'] = city_list[x]
console.log(More_Temp_count_copy['city'])
More_Temp_count_copy['posterity_name'] = poster_name.replace(city,city_list[x])
More_Temp_count_copy['blackwidow_task']['redis_key'] = redis_key.replace(city,city_list[x])
More_Temp_count_copy['blackwidow_task']['task_id'] = task_id.replace(city,city_list[x])
More_Temp_count_copy['blackwidow_task']['blackwidow_output']['db_config_test'] = key_test.replace(city,city_list[x])
More_Temp_count_copy['blackwidow_task']['blackwidow_output']['db_config'] = key_db.replace(city,city_list[x])
console.log('Prepare multiple new copy template information',More_Temp_count_copy["city"])
console.log('2')
}
——- - then I think it's because of asynchronous request, and then add each value to a list, and get it through index, but it's still wrong
——- in the end, the company's boss solved the problem because js's = assignment directly assigned the memory address of the object, so changing the parameter more'temp'count'is equivalent to changing this.more'temp'count, which leads to the problem. The solution is to use deep copy, directly convert the object to a string, and then copy the string, In this way, there will be no problem of assignment failure. Modify one line of code
// Reassign every cycle
var More_Temp_count_copy = JSON.parse(JSON.stringify(this.More_Temp_count))
Problem solving!