I would like to use a each function in my script but this function is used in an object which means it returns an error... The object I want to use each in is newPlots.
Maybe you know a trick?
I want to add plots in newPlots by using the content returned by AJAX. In plain text, newPlots look like this :
var newPlots = {
"City" : {
x : 45.834444,
y : 1.261667,
text : {content : "City"},
tooltip : {content : "City"}
}
, "City2" : {
size:60,
x : 47.323056,
y : 5.041944,
text : {
content : "City",
position : "left",
margin : 5
}
}
}
And the thing I want to do is using each function in newPlots.
Here you can find my code :
$.ajax({
type: "post",
url: '<?php echo $this->Url->build(array('controller'=>'Villes','action'=>'viewresult')); ?>',
data: {
departements: dptcode
},
dataType : "json",
success: function (ret) {
// Update some plots and areas attributes ...
var updatedOptions = {'plots' : {}};
// add some new plots ..
var newPlots = {
$.each(ret, function(index, element) {
"Limoge" : {
x : element.x,
y : element.y,
text : {content : "Limoge"},
tooltip : {content : "Limoge"}
},
});
}
// and delete some others ...
var deletedPlots = [];
$(".mapcontainer").trigger('update', [updatedOptions, newPlots, deletedPlots, {animDuration : 1000}]);
},
error : function(xhr, textStatus, errorThrown) {
alert('An error occurred! ' + errorThrown);
}
});