首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PolymerJS发布JSON格式

PolymerJS发布JSON格式
EN

Stack Overflow用户
提问于 2015-05-22 19:04:51
回答 1查看 62关注 0票数 0

我试图使用PolymerJS ajax-forms发布文章,但遇到了一个奇怪的JSON格式错误。有人能告诉我为什么钥匙周围缺少引号吗?我能想到的唯一解决办法是用键周围的引号手动构造主体。

代码片段:如何接收值(rest与更改的ids相同):

代码语言:javascript
复制
<div>
        <paper-input label="Title" id="course-title" floatingLabel value="{{item.title}}"></paper-input>
    </div>

 <access-core-ajax
              auto = "false"
              url="domain/courses"
              response="{{response}}"
              method="post"
              id="postCourse"
              contentType="application/json"
              headers='{"Accept": "application/json", "Content-Type":"application/json"}',
              body = "{{item}}">

            <template id="get-response-template" repeat="{{item in response.entries}}">
                    <p>Errors</p>
            </template>
        </access-core-ajax>

Polymer('create-new-course-page',{
        domReady: function() {
            console.log("Log: create-new-courses-page - Looks like we are domReady");
        },
        created: function() {
            console.log("Item initialized");
            this.item = {};
            this.data={};
        },
        createNewCourse: function(event) {
            console.log("HERE IS BODY", this.item);
            this.$.postCourse.go();


       }

在日志中可以看到JSON:

{标题:"WRU",// key & values,其中键没有"“}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-23 05:37:03

您需要首先将主体转换为JSON字符串。JSON.stringify可以帮上忙。

代码语言:javascript
复制
...
createNewCourse: function(e) {
    this.$.postCourse.body = JSON.stringify(this.item);
    this.$.postCourse.go();
}

您可能需要在这里移除body属性。您还可以删除该auto属性,因为默认情况下它是false。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30404138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档