I have a backbone.js project. I use jquery$get function inside. I am changing the value of the variable defined above in get. But when I do console.log (cityValue) outside, I see the old value.Can you help me? I look forward to your ideas.
Sample code;
getFormattedAddress1: function () {
var postalCodeValue = this.model.get(this.postalCodeField);
var streetValue = this.model.get(this.streetField);
var cityValue = this.model.get(this.cityField);
var stateValue = this.model.get(this.stateField);
var countryValue = this.model.get(this.countryField);
$.get("Target/action/city", { id : cityValue },function(data){
cityValue = data.name;
});
console.log(cityValue);
var html = '';
if (streetValue) {
html += streetValue;
}
if (cityValue || stateValue || postalCodeValue) {
if (html != '') {
html += '\n';
}
if (cityValue) {
html += cityValue;
}
if (stateValue) {
if (cityValue) {
html += ', ';
}
html += stateValue;
}
if (postalCodeValue) {
if (cityValue || stateValue) {
html += ' ';
}
html += postalCodeValue;
}
}
if (countryValue) {
if (html != '') {
html += '\n';
}
html += countryValue;
}
return html;
},