使用dart中的括号表示法访问对象的属性 [英] Get access to an object's property using bracket notation in dart

查看:395
本文介绍了使用dart中的括号表示法访问对象的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试执行以下操作:

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

但是dart似乎不接受此括号符号,是否还有其他符号使用dart中的字符串访问属性的方法?

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

推荐答案

您可以使用 getPropertyValue setProperty 这样的方法

You can use the getPropertyValue and setProperty methods like

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

这篇关于使用dart中的括号表示法访问对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆