聚合物铁AJAX:如何绑定数据输入元素铁阿贾克斯的身体属性 [英] polymer iron-ajax : How to Bind data from input element to iron-ajax's body attribute

查看:271
本文介绍了聚合物铁AJAX:如何绑定数据输入元素铁阿贾克斯的身体属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近有问题,从输入元素将数据绑定到铁阿贾克斯的身体的属性。 当我使用的核心AJAX聚合物0.5,我可以很容易地将值绑定是这样的:

I recently have problems binding data from input element to iron-ajax's "body" attribute. When I used core-ajax on polymer 0.5, I can easily bind values like this:

<core-ajax
           id="ajax"
           method="POST" 
           contentType="application/json"
           url="{{url}}"   
           body='{"username":"{{username}}", "password":"{{password}}"}'
           handleAs="json"
           on-core-response="{{responseHandler}}">
</core-ajax>

现在我想同样的事情用铁阿贾克斯。但它发出字面意思是{{用户名}},而不是和{{密码}}他们的价值观。这里是code:

Now I tried the same thing with iron-ajax. But it sends literally "{{username}}" and "{{password}}" instead of their values. Here is the code:

<iron-ajax
           id="ajax"
           method="POST" 
           contentType="application/json"
           url="{{url}}"   
           body='{"username":"{{username}}", "password":"{{password}}"}'
           handle-as="json"
           on-response="responseHandler">
</iron-ajax>

如何使它工作?谢谢您的回答:)

How to make it work? Thank you for your answers :)

推荐答案

您可以声明一个计算的属性阿贾克斯身上。像这样

You can declare a computed property for the ajax body. Like so

properties: {
    ...
    ajaxBody: {
        type: String,
        computed: 'processBody(username, password)'
    }
},
processBody: function(username, password) {
    return JSON.stringify({username: username, password:password});
}

然后将它添加在铁AJAX

And then adding it on iron-ajax

<iron-ajax ... body="{{ajaxBody}}"></iron-ajax>

这篇关于聚合物铁AJAX:如何绑定数据输入元素铁阿贾克斯的身体属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆