如何使用javascript访问函数中传递的对象参数?我想动态使用各种 column_name。feature.attribute 有列名。我想将feature.attribute与column name连接起来。到目前为止,我已经尝试过:
我的代码:
var column_name = "LOCAL_POP";
var initialize = {
init_style: function() {
style = new OpenLayers.StyleMap({
"default": new OpenLayers.Style(
{
fillColor: "${getColor}",
strokeColor: "#00FF01",
fillOpacity: 0.7,
graphicZIndex: 1,
label: "${DISTRICT}"
},
{
context: {
getColor: function(feature) {
**// tested by creating a local variable and window variable**
this.feature = feature;
var feature_name = 'feature.attributes.' + column_name;
console.log(window);
console.log(this['feature_name']);
console.log(window['feature_name']);
return feature_name > 1000000 ? '#006D2C' :
feature_name > 100000 ? '#31A354' :
feature_name > 5000 ? '#74C476' :
feature_name >= 0 ? '#A1D99B' :
'';
}
}
}),
"select": new OpenLayers.Style(
{
strokeColor: "#00FF01",
fillOpacity: 0.7
})
});
return style;
}
};