2015-09-14 72 views
1

我试图通过对象数组使用聚合物1.0 <iron-ajax>一个DOM重复的内部

<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"> 
 
\t <template> 
 
\t \t <template is="dom-repeat" as="plugin" items="{{plugins}}"> 
 
\t \t \t <template is="dom-if" if="{{plugin.sidenav}}"> 
 
\t \t \t \t <iron-ajax auto url="{{_generatePluginUrl(plugin)}}" handle-as="text" last-response="{{plugin.ajax}}"></iron-ajax> 
 
\t \t \t \t <html-echo html="{{plugin.ajax}}"></html-echo> 
 
\t \t \t </template> 
 
\t \t </template> 
 
\t </template> 
 
\t <script> 
 
\t \t Polymer({ 
 
\t \t \t is: 'sidenav-list', 
 
\t \t \t ready: function() { 
 
\t \t \t \t this.plugins = allAddons(); 
 
\t \t \t }, 
 
\t \t \t _generatePluginUrl: function(plugin) { 
 
\t \t \t \t var newURL = "./plugins/" + plugin.folder + "/" + plugin.file; 
 
\t \t \t \t return newURL; 
 
\t \t \t }, 
 
\t \t }); 
 
\t </script> 
 
</dom-module>

的问题是,是我设置last-response="pluginAjax"我结束了重复,当我把它设置为plugin.ajax结果就是不确定的。

回答

2

从文档(通过注释) - 链接到这里,因为文档查看器不允许直接链接到dom-repeat文档页面。

https://github.com/Polymer/polymer/blob/0f8483da48dc3747f3c4bdd439b95c4bce2897d7/src/lib/template/dom-repeat.html#L59s

您可以在您的内部响应处理的功能使用

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); 
    } 
}); 
+0

谢谢,精美的作品:d – Irontiga