google-app-engine - 在没有 JsProxy 的情况下使 Dart-Polymer 模型类可反射

标签 google-app-engine dart google-cloud-datastore dart-polymer

我有一个在 AppEngine 上运行的 dart 服务器和一个 Dart-Polymer 客户端。这个想法是共享共同的逻辑,例如模型。但是,有一个小问题。通常你会让你的模型类扩展JsProxy而不是用 @reflectable 注释所有相关字段为了在数据绑定(bind)中使用它们。不幸的是,与 AppEngine 的数据存储一起使用的模型已经继承自模型。除此之外,我不确定dart:js在服务器上可用。因此,我必须找到另一种方法来使我的模型可反射(reflect)在 UI 中。

使用 @reflectable 注释 Project#name 不起作用。与输出相同的空 div。

在模型中包含 JsProxy 时:

The built-in library 'dart:html' is not available on the stand-alone VM.



有任何想法吗?
@Kind(name: 'Project', idType: IdType.Integer)
class Project extends Model {

  @StringProperty(required: true)
  String name;

}

@PolymerRegister('project-list')
class ProjectList extends PolymerElement {

  @property List<Project> projects;

  ProjectList.created() : super.created();

  ready() {
    fetchProjects();
  }
}

<dom-module id="projects-page">
  <template>
    <template is="dom-repeat" items="{{projects}}">
      <div>{{item.name}}</div>
    </template>
  </template>
</dom-module>

输出:
<div></div>

最佳答案

这是一个已知问题 https://github.com/dart-lang/polymer-dart/issues/664

到目前为止,最好的解决方法是使用应用了注释并包装共享模型类的代理对象。

class FooProxy extends JsProxy implements Foo {
  final Foo model;

  FooProxy(this.model);

  @reflectable
  int get bar => model.bar;
  set(int value) { model.bar = value}
}

关于google-app-engine - 在没有 JsProxy 的情况下使 Dart-Polymer 模型类可反射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37052146/

相关文章:

flutter - 当int通常为32或64位时, “int”如何表示一个字节(8位)?

go - 如何从数据存储中获取名称/ key

google-app-engine - GAE Go - 如何将私有(private)变量放入数据存储区?

google-app-engine - AppEngine 的 RESTFul 服务框架

google-app-engine - 祖先在谷歌应用引擎数据存储中意味着什么

java - 增加我在 Google App Engine 上所有应用程序 ID 的电子邮件配额

Java、Google App Engine 和 JSONArray/JSONObject

Python StructuredProperty 到字典

dart - flutter 如何弹出动态页面?

scala - Dart 中优雅的错误处理,如 Scala 的 `Try`