follow my code
var canvasEvents = new Object;
canvasEvents['05-30-2015'] = '<a href="#" target=_blank>CAMPEONATOS SUL-AMERICANOS DE ATLETISMO</a>';
$.getJSON('http://www.atletismope.com.br/eventos/lista', function(eventos) {
$.each(eventos, function(index, evento) {
canvasEvents["04-20-2015"] = '<a href="#" target=_blank>CAMPEONATOS SUL-AMERICANOS DE ATLETISMO</a>';
});
});
canvasEvents["04-25-2015"] = '<a href="#" target=_blank>CAMPEONATOS SUL-AMERICANOS DE ATLETISMO</a>';
When canvasEvents is added inside the looping does not work, but if we add outside the looping it works. Why?
There is a plugin that uses this object, jquery.calendario.js. The assignment of the object only works if I put an alert outside the loop. Here is the code that is working. You can view the result in this url: link
var canvasEvents = new Object;
$.getJSON('http://www.atletismope.com.br/eventos/lista', function(eventos) {
$.each(eventos, function(index, evento) {
var data = evento.data;
var data_f = data.substr(5,2) + '-' + data.substr(8,2) + '-' + data.substr(0,4);
canvasEvents[data_f] = '<a href="#" target=_blank>'+ evento.titulo +'</a>';
});
});
alert(canvasEvents); //nao funciona sem o alert