dom-重复内的聚合物 1.0 <iron-ajax>
Polymer 1.0 <iron-ajax> inside of a dom-repeat
我正在尝试使用
<template is="dom-repeat" as="plugin" items="{{plugins}}">
循环对象数组,然后为数组中的每个对象生成一个 url 以从中获取数据。我要将这些数据放入页面中。
我的元素是这样的:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<script src="../../scripts/plugins.js"></script>
<dom-module id="sidenav-list">
<template>
<template is="dom-repeat" as="plugin" items="{{plugins}}">
<template is="dom-if" if="{{plugin.sidenav}}">
<iron-ajax auto url="{{_generatePluginUrl(plugin)}}" handle-as="text" last-response="{{plugin.ajax}}"></iron-ajax>
<html-echo html="{{plugin.ajax}}"></html-echo>
</template>
</template>
</template>
<script>
Polymer({
is: 'sidenav-list',
ready: function() {
this.plugins = allAddons();
},
_generatePluginUrl: function(plugin) {
var newURL = "./plugins/" + plugin.folder + "/" + plugin.file;
return newURL;
},
});
</script>
</dom-module>
问题是我设置了 last-response="pluginAjax"
结果是重复的,当我将它设置为 plugin.ajax
时结果是未定义的。
来自文档(通过评论)——链接到这里是因为文档查看器不允许直接链接到 dom-repeat 文档页面。
您可以通过使用
来实现这个目标
event.model.set('item.ajax, event.detail.response)
在您的响应处理函数中。
即:
如果你的熨斗-ajax 看起来像这样:
<iron-ajax auto url="{{_generatePluginUrl(plugin)}}" handle-as="text"
on-response="_hresponse"></iron-ajax>
然后您的元素中的处理程序将如下所示:
Polymer({
//...
_hresponse: function(request){
request.model.set('plugin.ajax', request.detail.response);
}
});
我正在尝试使用
<template is="dom-repeat" as="plugin" items="{{plugins}}">
循环对象数组,然后为数组中的每个对象生成一个 url 以从中获取数据。我要将这些数据放入页面中。
我的元素是这样的:
<link rel="import" href="../../bower_components/polymer/polymer.html">
<script src="../../scripts/plugins.js"></script>
<dom-module id="sidenav-list">
<template>
<template is="dom-repeat" as="plugin" items="{{plugins}}">
<template is="dom-if" if="{{plugin.sidenav}}">
<iron-ajax auto url="{{_generatePluginUrl(plugin)}}" handle-as="text" last-response="{{plugin.ajax}}"></iron-ajax>
<html-echo html="{{plugin.ajax}}"></html-echo>
</template>
</template>
</template>
<script>
Polymer({
is: 'sidenav-list',
ready: function() {
this.plugins = allAddons();
},
_generatePluginUrl: function(plugin) {
var newURL = "./plugins/" + plugin.folder + "/" + plugin.file;
return newURL;
},
});
</script>
</dom-module>
问题是我设置了 last-response="pluginAjax"
结果是重复的,当我将它设置为 plugin.ajax
时结果是未定义的。
来自文档(通过评论)——链接到这里是因为文档查看器不允许直接链接到 dom-repeat 文档页面。
您可以通过使用
来实现这个目标event.model.set('item.ajax, event.detail.response)
在您的响应处理函数中。
即: 如果你的熨斗-ajax 看起来像这样:
<iron-ajax auto url="{{_generatePluginUrl(plugin)}}" handle-as="text"
on-response="_hresponse"></iron-ajax>
然后您的元素中的处理程序将如下所示:
Polymer({
//...
_hresponse: function(request){
request.model.set('plugin.ajax', request.detail.response);
}
});