问题描述
$ b b
ownerName
只是聚合物元素上的已发布属性。我知道这里有一些东西(在网上,不在这里),像这样,但没有一个坚实的答案...
ownerName
is just an published attribute on the polymer element. I understand there are a few things out there (on web, not on here) like this but none have a solid answer...
我也得到这下面它:
任何人都有任何想法。摔跤这个3个小时,准备转储聚合物。虽然在dartium很有趣,但如果它不能转换为JS,我看不到它的真正用途。
Anyone got any ideas. Been wrestling with this for 3 hours and ready to dump polymer. Though It was fun in dartium, if it cannot convert to JS I see no real use in it.
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元素
The HTML Polymer element
<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>
推荐答案
我还没有看到你的不支持的操作
消息。也许最近的一些变化。当类的属性仅由聚合表达式(HTML)引用时, NoSuchMethodError
是常见的,因为树形抖动丢弃所有未引用的代码,并且未评估聚合物表达式为此。 @MirrorsUsed
注释有助于弥补这一差距。
I have not yet seen your Unsupported operation
message. 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. The @MirrorsUsed
annotation helps bridging this gap.
问题出现在 / code> class,因为它的属性只在聚合表达式中引用
The problem is in your Post
class because it's properties are only referenced in polymer expressions
<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
更改你应该使 Post
类像
class Post extends Object with Observable {
@observable String ownerName;
@observable String title;
...
}
如果您有注释,例如 @reflectable
, @published
或 @observable
@MirrorsUsed
。
If you have an annotation like @reflectable
, @published
, or @observable
you don't need @MirrorsUsed
.
这篇关于在聚合物项目上获取转换dart2js的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!