Я пишу элемент Полимер, который собирает информацию из API и который он должен распространять на дочерние элементы на основе ключей объектов результата.Как отображать информацию из родительского объекта в Polymer?
Элемент my-parent
выполняет вызов ajax. Ответ, если он получен в функции response()
.
Мой вопрос заключается в следующем: как я могу хранить полученную информацию таким образом, чтобы я мог распространять и отображать ее дочернему элементу?
App.html
<my-parent collector="1">
<h1>The Results</h1>
<h3><my-child name="title"><!-- should output FOO --></my-child></h3>
<h3><my-child name="description"><!-- should output BAR --></my-child></h3>
</my-parent>
мой-parent.html
<dom-module id="my-parent">
<template>
<style>
:host {
display: block;
}
</style>
<content></content>
<iron-ajax auto url="//someurl/posts/[[collector]]" handle-as="json" last-response="{{response}}" on-response="onResponse" id="xhr"></iron-ajax>
</template>
<script>
Polymer({
is: 'my-parent',
properties: {
collector: {
type: String,
notify: true
},
response: {
type: String
}
},
onResponse: function(response){
/* WHAT TO DO HERE? */
}
})
</script>
</dom-module>
результат API от //someurl/posts/1
{
"title": "FOO",
"description": "BAR"
}
мой-child.html
<dom-module id="my-child">
<template>
<style>
:host {
display: block;
}
</style>
{{itemes}}
</template>
<script>
Polymer({
is: 'my-child',
properties: {
itemes: {
type: String,
value: function(){
return "what to do here?";
}
}
},
key: {
type: String,
notify: true
}
})
</script>
</dom-module>