I have an object named path which is:
var path = { "firstFloor": ["roomA1", "roomA6", "roomA5", "roomA2", "roomA3", "roomA4", "roomA10"],
"secondFloor": ["roomB4", "roomB5", "roomB6"],
"basementFloor": []}
right now I'm selecting the arrays normally (path.firstFloor etc.), but I need to select these pairs in a function with the key as the parameter, so:
function draw(floor) { //later on I will call this function with parameter firstFloor
$(path.floor).each(function(i, val){ //this is where I need to select.
var roomIdPath = path.firstFloor[i]
//console.log(roomIdPath);
var points = d3.select('#'+roomIdPath).attr('points').split(",");
var midX = (Number(points[0]) + Number(points[6])) / 2;
var midY = (Number(points[1]) + Number(points[3])) / 2;
floorArray.push({"x": midX, "y": midY});
});
}
Not sure if I'm being clear, basically, all I need is a way to use function parameter in jQuery selector. Is there anyway to do that?