Blondinka,
А так нельзя?
var forma = {
model:{
userLocationCity: "",
userLocationCountry: "",
userLocationRegion: "",
getUserLocation: function(){
$.getJSON('http://ipinfo.io', function(data) {
if (data) {// If data exist.
forma.model.userLocationCity = data.city;
console.log(forma.model.userLocationCity);//Work
forma.model.userLocationCountry = data.country;
forma.model.userLocationRegion = data.region;
forma.view.render();
} else {
}
});
}
},
view:{
render: function(){
//Put data from the model in the form.
$("input[name~='country']").val("Ukraine"); //Works.
$("input[name~='city']").val(forma.model.userLocationCity); //Doesn't work
$("input[name~='region']").val(forma.model.userLocationRegion); //Doesn't work
alert("It's allive! "+forma.model.userLocationCountry); //Doesn't work
}
},
controller: {
init: function(){
forma.model.getUserLocation();
}
}
};
forma.controller.init();