Iron-ajax数据绑定 [英] Iron-ajax Data binding

查看:44
本文介绍了Iron-ajax数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在新的Polymer v1.0中进行数据绑定?

How to data bind in the new Polymer v1.0?

我在但这对我没有帮助,这是我的代码

But it did not help me and Here is my code

<dom-element id="test-app> 
<template>
...
<iron-ajax
auto
url="https://www.googleapis.com/youtube/v3/search"
params="{{ajaxParams}}"
handleAs="json" lastResponse="{{response}}"
method='GET'>
</iron-ajax>
</template>
</dom-module>

脚本

Polymer({
        is:"Test-app",

        properties: {
            qry: {
                type: String,
                value: 'Cat'
            },
            key1: {
                type: String,
                value: 'myapikey'
            },
            part1: {
                type: String,
                value: 'snippet'
            },
            maxResults1: {
                type: Number,
                value: 10
            },
            ajaxParams: {
                type: String,
                computed: 'processParams(part1, qry, maxResults1, key1)'
            }
        },
        processParams: function(part1, qry, maxResults1, key1){
            var param = JSON.stringify({part: part1, q:qry, maxResults: maxResults1, key:key1});
            console.log(param);
            return param;
        }
    });
</script>

我在控制台中以JSON字符串的形式获得了正确的日志,但是在返回此值时,该值是按字面值(与上面提供的链接中所述的问题相同)而不是它的值.

I get the correct log in console as a JSON string, but when this value is being returned, the value is taken literally (same problem as told in the link provided above) and not as its value.

我在控制台中收到一个错误,因为请求代码错误400.我们非常感谢您的帮助.

I get an error in console as bad request code 400. Any help is highly appreciated.

推荐答案

属性params的类型为Object.与链接的示例不同,您只能返回一个本机对象.

The property params is of type Object. Unlike in the linked example, you can just return a native object.

processParams: function(part1, qry, maxResults1, key1) {
    return {
        part: part1,
        q: qry,
        maxResults: maxResults1,
        key:key1
    };
}

这篇关于Iron-ajax数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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