【发布时间】:2015-12-08 19:44:03
【问题描述】:
我对 Polymers iron-ajax 元素有疑问。 当这样调用它时:
<iron-ajax url="https://api.onedrive.com/v1.0/drive/root" params='{"access_token":"[[access_token]]"}'></iron-ajax>
它发送一个这样的 url,将整个 params 字符串拆分为多个参数:
https://api.onedrive.com/v1.0/drive/root?0="&1=a&2=c&3=c&4=e&5=s&6=s&7=_&8=t&9=o&10=k&11=e&12=n&13="...
当使用普通字符串作为参数时,它可以正常工作,所以我猜引号是正确的。
使用 iron-ajax 的 Element 脚本部分:
<script>
Polymer({
is: 'onedrive-files',
properties: {
access_token: String
},
ready: function() {
},
});
</script>
我这样称呼元素:
<onedrive-files access_token="testtoken">
</onedrive-files>
有人有什么想法吗? 谢谢!
编辑: 使用 getter 函数:
<dom-module id="onedrive-files">
<template>
<iron-ajax id="ajax" url="https://api.onedrive.com/v1.0/drive/root" last-response="{{data}}" params='{{_getParams()}}' auto></iron-ajax>
</template>
<script>
Polymer({
is: 'onedrive-files',
properties: {
access_token: String
},
_getParams: function()
{
return ('{"access_token":"' + this.access_token + '"}');
},
ready: function() {
this.$.ajax.generateRequest();
},
});
</script>
</dom-module>
在Ready函数中设置参数:
<dom-module id="onedrive-files">
<template>
<iron-ajax id="ajax" url="https://api.onedrive.com/v1.0/drive/root" last-response="{{data}}" auto></iron-ajax>
</template>
<script>
Polymer({
is: 'onedrive-files',
properties: {
access_token: String
},
ready: function() {
this.$.ajax.params = '{"access_token":"' + this.access_token + '"}';
},
});
</script>
</dom-module>
【问题讨论】:
-
这里有同样的问题。不幸的是,它也弄乱了我的查询,但我认为这应该在未来的版本中修复。
-
我在使用 Iron ajax 2.0 时遇到了同样的问题!我想知道什么给了。
标签: polymer polymer-1.0