[英]Getting error converting dart2js on polymer project
Unsupported operation: Can't use ownerName in reflection because it is not included in a @MirrorsUsed annotation.
不支持的操作:无法在反射中使用ownerName,因为它未包含在@MirrorsUsed注释中。
ownerName
is just an published attribute on the polymer element. ownerName
只是聚合物元素的已发布属性。 I understand there are a few things out there (on web, not on here) like this but none have a solid answer... 我知道有一些东西(在网上,而不是在这里)像这样,但没有一个有一个坚实的答案......
I also get this below it: 我也在下面得到它:
NoSuchMethodError : method not found: 'Symbol("title")'
NoSuchMethodError:找不到方法:'符号(“标题”)'
Anyone got any ideas. 任何人都有任何想法。 Been wrestling with this for 3 hours and ready to dump polymer.
与此摔跤3个小时,准备倾倒聚合物。 Though It was fun in dartium, if it cannot convert to JS I see no real use in it.
虽然它在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() {
}
}
The HTML Polymer element HTML Polymer元素
<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>
I have not yet seen your Unsupported operation
message. 我还没有看到您的
Unsupported operation
消息。 Maybe some recent change. 也许最近有些变化。 Your
NoSuchMethodError
is common when a property of a class is only referenced by a polymer expression (HTML) because tree-shaking drops all code that is not referenced and polymer expressions are not evaluated for this yet. 当类的属性仅由聚合表达式(HTML)引用时,
NoSuchMethodError
很常见,因为树抖动会丢弃所有未引用的代码,并且聚合物表达式尚未针对此进行评估。 The @MirrorsUsed
annotation helps bridging this gap. @MirrorsUsed
注释有助于弥合这一差距。
The problem is in your Post
class because it's properties are only referenced in polymer expressions 问题出在
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>
To get your view updated when the properties in your currentPost
change you should make your Post
class like 要在
currentPost
的属性发生更改时更新视图,您应该使Post
类更新
class Post extends Object with Observable {
@observable String ownerName;
@observable String title;
...
}
If you have an annotation like @reflectable
, @published
, or @observable
you don't need @MirrorsUsed
. 如果你有一个像注释
@reflectable
, @published
,或@observable
你不需要@MirrorsUsed
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.