我试图将一个局部变量(一个字典)传递给一个D3过滤器函数,但是这样做却收效甚微。
d3appendedElement.on("click", function(d){
var county_list = state_retriever[d.id];
//county_list is a dictionary:
//county_list = {"56001": true, "56003": true, "56005": true,...}
embedGroup.filter(function(e){
console.log(e);
//e = ["16079", -0.36402252840408394, -0.5303157467831482]
//here, I would like to have access to county_list. However, I do not.
//The following does not work; I get
// `Uncaught ReferenceError: county_list is not defined`
return e[0] in county_list;
});
}
county_list
是与true
匹配的字符串字典。 embedGroup
是d3对象,我尝试根据它是否在["16079", -0.36, -0.53]
字典中过滤每个数据点( 16079 上的过滤器county_list
)。
有没有办法在不将county_list
作为全局变量的情况下执行此操作?