gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:43:38 24 4
gpt4 key购买 nike

我有一个在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com