我正在为一个干净的RESTful服务层构建基于Polymer的前端原型。我想我已经有了组件级的AJAX工作,但它并没有绘制到Shadow DOM ...相反,我在Chrome中遇到错误:Uncaught SyntaxError:意外的令牌。来自base.js:164(root.appendChild(dom))。
我的代码:
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/core-ajax/core-ajax.html">
<polymer-element name="feed-posts">
<template>
<link rel="stylesheet" href="/assets/css/bootstrap.min.css">
<link rel="stylesheet" href="/assets/css/styles.css">
<core-ajax id="stream" url="https://api.myhost.com/1/streams" handleAs="json" params=" {{ streamparams }}" auto on-core-response="{{ feedLoaded }}"></core-ajax>
<template repeat="{{f in feed }}">
<div class="tile">
<div class="heroTop">
<div class="headline">Post ID is {{ f }}</div>
</div>
</div>
</template>
<script>
Polymer('#stream', {
accesstoken: document.querySelector('app-globals').accesstoken,
userid: document.querySelector('app-globals').userid,
streamparams: { "access_token": this.accesstoken, "user_id": this.userid }
});
</script>
</template>
<script>
Polymer('newsfeed-posts', {
created: function(){
this.feed = [];
},
feedLoaded: function(){
this.feed = this.$.stream.response['post_ids'];
}
});
</script>
</polymer-element>
这是聚合物的错误,还是(无限可能)用户错误?
答案 0 :(得分:0)
您的代码:
Polymer('#stream', {
this.accesstoken = document.querySelector('app-globals').accesstoken;
this.userid = document.querySelector('app-globals').userid;
this.streamparams = {
"access_token": this.accesstoken,
"user_id": this.userid
};
});
至少应该是这样的:
Polymer('#stream', {
accesstoken: document.querySelector('app-globals').accesstoken,
userid: document.querySelector('app-globals').userid,
streamparams: {
"access_token": this.accesstoken,
"user_id": this.userid
},
});
使用代码linter,您甚至可以在运行代码之前找到这些错误(语法错误)。
但是,您的代码中存在更多错误。来吧,阅读真棒polymer docs。