gpt4 book ai didi

dart - 在聚合物项目上转换 dart2js 时出错

转载 作者:行者123 更新时间:2023-12-05 01:08:20 25 4
gpt4 key购买 nike

Unsupported operation: Can't use ownerName in reflection because it is not included in a @MirrorsUsed annotation.

ownerName 只是聚合物元素上的已发布属性。我知道那里有一些东西(在网上,而不是在这里),但没有一个有可靠的答案......

我也在下面得到这个:

NoSuchMethodError : method not found: 'Symbol("title")'

任何人都有任何想法。与此搏斗了 3 个小时,并准备倾倒聚合物。虽然它在 dartium 中很有趣,但如果它不能转换为 JS,我看不出它有什么实际用处。

import 'package:polymer/polymer.dart';
import 'package:google_postendpoint_v1_api/postendpoint_v1_api_browser.dart';
import 'package:google_postendpoint_v1_api/postendpoint_v1_api_client.dart';
import 'dart:math';
//import 'package:intl/intl.dart';


/**
* A Polymer post element.
*/
@CustomTag('post-element')
class SoberSky extends PolymerElement {
@published int count = 0;
@published String ownerName = "Casey";
@published int ownerId = 888;
@published int postId = 333;
@published String content = "yo ho ho, and a bottle of rumsky!";
@published String postContent = "This is an example of post content";

@published int getOwnerId = 333;
@published CollectionResponse_Comment listComment;
@published CollectionResponse_Post listPost;
@published String listCommentHTML;
@published Post currentPost;
@published bool yes = false;
Postendpoint endpoint = new Postendpoint();
var rng = new Random();

var commentList;

SoberSky.created() : super.created() {
endpoint.rootUrl = "http://localhost:8888/"; // set the root URL
}

void getListComment([int tempPostId]) {
if (tempPostId == null) {
tempPostId = postId;
}
endpoint.listComment( tempPostId ).then((CollectionResponse_Comment commentCollection){
this.listComment = commentCollection;
}).catchError((e) => handleError(e));
}

void getPost() {
endpoint.getPost( postId ).then((Post loadedMessage) {
currentPost = loadedMessage;
getListComment(currentPost.key);
}).catchError((e) => handleError(e));
}

void submitComment() {
int id = rng.nextInt(1000);
Comment comment = new Comment.fromJson({});
comment.id = id;
comment.content = content;
comment.postId = postId;
comment.ownerName = ownerName;
comment.ownerId = ownerId;

endpoint.insertComment( comment ).then((Comment savedComment) => endpoint.getComment(id)).
then((Comment loadedMessage) {
print(loadedMessage.content);
getListComment(loadedMessage.postId);
}).catchError((e) => handleError(e));
}

void submitPost(){
postId = rng.nextInt(1000);
Post post = new Post.fromJson({});
post.key = postId;
post.ownerName = ownerName;
post.ownerId = ownerId;
post.title = postContent;

endpoint.insertPost( post ).then((Post savedPost) => endpoint.getPost(postId)).
then((Post loadedMessage) {
print(loadedMessage.title);
getPost();
getListComment(loadedMessage.key);
}).catchError((e) => handleError(e));
}

void handleError(Error e) {
print("We had an error: ");
print(e.toString());
}

@override
void attached() {
}
}

HTML 聚合物元素

<polymer-element name="click-counter" attributes="count">
<template>
<form action="javascript:void(0);" >
<div class="entry">
<label>Enter Post:</label>
<input id="subject" type="text" value="{{postContent}}" size="45" maxlength="255">
<button on-click="{{submitPost}}" class="btn btn-success" >Submit Post</button> <br>

</div>
</form>
<div class="post">
<h3>{{ currentPost.ownerName }}</h3>
<p>{{ currentPost.title }}</p>
<p>This is the postId: {{ currentPost.key }}</p>
<p class="timestamp">{{ currentPost.uploadTime }}</p>
<template repeat="{{comment in listComment.items}}">
<div class="comment">
<h3>{{ comment.ownerName }}</h3>
<p>{{ comment.content }}</p>
<p>This is the commentId: {{ comment.id }}</p>
<p class="timestamp">{{ comment.formatDate }}</p>
</div>
</template>
<form action="javascript:void(0);">
<label>Enter Comment:</label>
<input id="subject" type="text" value="{{content}}" size="45" maxlength="255">
<button on-click="{{submitComment}}" class="btn btn-success">Submit Comment</button> <br>
</form>
</div>
</template>
<script type="application/dart" src="clickcounter.dart"></script>
</polymer-element>

最佳答案

我还没有看到您的 Unsupported operation 消息。也许最近发生了一些变化。当类的属性仅被聚合物表达式 (HTML) 引用时,您的 NoSuchMethodError 很常见,因为 tree-shaking 会丢弃所有未被引用的代码,并且聚合物表达式尚未为此评估。 @MirrorsUsed 注释有助于弥合这一差距。

问题出在您的 Post 类中,因为它的属性仅在聚合物表达式中引用

<div class="post">  
<h3>{{ currentPost.ownerName }}</h3>
<p>{{ currentPost.title }}</p>
<p>This is the postId: {{ currentPost.key }}</p>
<p class="timestamp">{{ currentPost.uploadTime }}</p>

要在 currentPost 中的属性更改时更新您的 View ,您应该将 Post 类设置为

class Post extends Object with Observable {
@observable String ownerName;
@observable String title;
...
}

如果你有像@reflectable@published@observable 这样的注解,你不需要@MirrorsUsed.

关于dart - 在聚合物项目上转换 dart2js 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20855777/

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