Infowindow Carto with content from local variable

2017-09-19 15:00:51

I'm quite new with Carto so this is probably a simple question, for that I'm sorry in advance!

I created a layer, this layer gets some sublayers created dynamically like this:

var data = getData();

for(var i = 0; i < sublayers.length; i++) {

layer.createSubLayer({

sql: "SELECT * ...",

cartocss: '...'

});

}

I want to add to each layer an infowindow with information from data. So instead of adding content from datasets is from that variable.

I've tried to use sublayer.infowindow.set({...}) and cdb.vis.Vis.addInfowindow(map, sublayer, ['name'], ...) but it's not what I am expecting.