b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

是否有一种方法来动态调用方式或在Dart中的类中设定范例变量?

电脑杂谈  发布时间:2020-03-14 04:02:51  来源:网络整理

动态调用webservice_动态方法调用 为什么不安全_class之间方法调用方法

问 题

I would want to be able to do something like this with a Dart class constructor:

class Model {
  // ... setting instance variables
  Model(Map fields) {
    fields.forEach((k,v) => this[k] = v);
  }
}

动态方法调用 为什么不安全_动态调用webservice_class之间方法调用方法

Obviously, this doesn't work, because this doesn't have a []= method.

Is there a way to make it work or is it simply not "the dart way" of doing things? If it's not, could you show me what would be the right way to tackle this?

解决方案

动态调用webservice_动态方法调用 为什么不安全_class之间方法调用方法

Currently no. You will have to wait for reflection to arrive in Dart before something like this (hopefully) becomes possible. Until then your best bet is probably to do it in a constructor. Alternatively you could try to use something like JsonObject which allows you to directly initialize it from a Map (for an explanation on how this works, check this blog post).

本文地址:IT屋 是否有一种方法来动态调用方式或在Dart中的类中设定范例变量?

问 题

动态方法调用 为什么不安全_class之间方法调用方法_动态调用webservice

我想用Dart类构造函数做这种的事情:

  class Model {

// ...设置实例变量

模型(映射字段){
fields.forEach((k,v)=>这个[k] = v);
}

}

显然动态方法调用 为什么不安全,这不工作,因为此没有 [] = 方法。

动态方法调用 为什么不安全_动态调用webservice_class之间方法调用方法

$ b b

有没有办法让它工作,或者它根本不是飞镖的方法做人情?

解决方案

目前没有。如果没有,您可告诉我什么是恰当的方式来缓解这个难题。你将不得不等待反射到达Dart在这种的东西(希望)成为或许。直到如今,你最好的打赌可能是在一个构造函数。或者,您可以尝试使用类似于 JsonObject 的方式,它允许您从地图直接初始化它为此工作原理的表明动态方法调用 为什么不安全,请查看此 blog post)。

本文地址:IT屋 是否有一种方法来动态调用方式或在Dart中的类中设定范例变量?


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-144082-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...