Get access to an object's property using brack

2019-05-14 14:40发布

问题:

I try to do the following:

var properties = ["height" , "width"];
for (var prop in properties){
  div.style[prop] = otherdiv.style[prop];
}

But dart doesn't seem to accept this bracket notation, is there any other way to access a property using a string in dart ?

回答1:

You can use the getPropertyValue and setProperty methods like

div.style.setProperty(prop, otherdiv.style.getPropertyValue(prop));