2017-10-12 82 views
0

我正在尝试做一个嵌套的dom-repeat,我没有任何错误,但仍然有空的显示。检查元素,我可以看到数据实际上在那里,并且页面在空白之前显示很短的时间。下面的代码摘录:nested dom-repeat什么也没有显示

 <iron-ajax auto url="http://localhost:8808/datal2" handle-as="json" last-response="{{top}}"></iron-ajax> 

    <template is="dom-repeat" items="{{top.top}}" as="item"> 
     <div> 
     <span id="l4-support-offering-[[index]]">{{item.l2}}</span> 
     </div> 


     <iron-ajax auto url="[[computeCompleteUrl(item.l2)]]" handle-as="json" last-response="{{top}}"></iron-ajax> 

     <template is="dom-repeat" items="{{top.top}}" as="level24" index-as="indexl24"> 
      <div> 
      <span id="l4-support-offering-l4[[indexl24]]">{{level24.l4}}</span> 
      </div> 
     </template> 
    </template> 

    <script> 

    ........ 
     properties: { 
    top: { 
     type: Array, 
     value: function() { return []; } 
    }, 
    level24: { 
     type: Array, 
     value: function() { return []; } 
    }, 
    ................ 

聚合物为v 1.8.0

我改变了代码:

<p> 
    Hello! 
</p> 
<iron-ajax auto url="http://localhost:8808/datal2" handle-as="json" last-response="{{lev2}}"></iron-ajax> 


    <template is="dom-repeat" items="{{lev2.top}}" as="iteml2"> 
     <span id="l4-support-offering-[[index]]">{{iteml2.l2}}</span><br> 

    <iron-ajax auto url="[[computeCompleteUrl(iteml2.l2)]]" handle-as="json" last-response="{{lev4}}"></iron-ajax> 
      <template is="dom-repeat" items="{{lev4.l4byl2}}" as="level4" index-as="indexl24"> 
       <span id="l4-support-offering-l4[[indexl24]]">{{level4.l4}}</span> 

      </template><br> 


</template> 
<script> 
Polymer({ 
    is: 'game', 

    properties: { 
    lev2: { 
     type: Array, 
     value: function() { return []; } 
    }, 
    lev4: { 
     type: Array, 
     value: function() { return []; } 
    } 
    }, 

    computeCompleteUrl: function(level) { 
    return 'http://localhost:8808/datal4byl2/' + level; 
    console.log("manager is:" +level); 
    }, 

现在我已经显示的东西,但它是不正确。我有一些像

X 1,2,3,4 Ÿ 1,2,3,4 ž 1,2,3,4

,而应该是(这只是一个例如)

X 8,2,4 ý 6,8,5,2 ž 1,2,3,4-

所以它总是填充的最后一个元素的从数据第一个列表。

回答

0

您正在参考top.top但该变量不存在。你的top属性是Array的类型,所以你不能这样做top.top。首先,你必须遍历throught top属性,然后在嵌套dom-repeat - item.top(也许你只是错误地复制你的代码)

+0

我改变了代码,所以也许现在更清晰一点。现在我在屏幕上获取数据,但是对于第一个循环中的每个元素,我有相同的第二个元素(对应于第一个循环的最后一个元素)。所以它是这样的:X(1,2,3,4),Y(1,2,3,4),Z(1,2,3,4),而它应该是X(1,3,4), Y(6,8,5,2),Z(9)。 – vlucian

+0

请查看我的更改。 – vlucian

+0

@vlucian,但仍然是一样..你正在重新考虑'lev2.top',但'lev2'是数组。所以javascript怎么才能访问'lev2.top'就是废话。另外,如果你添加了这些数组及其结构的例子将会很好。否则当你的示例代码 –

0

在它的工作后,我改变了第二DOM重复到最后:

<template is="dom-repeat" items="{{getLevelFours(item.l2)}}" as="level24" index-as="indexl24"> 

和使用的功能:

computeCompleteUrl: function(level) { 
    return 'http://localhost:8808/datal4byl2/' + level; 
    }, 
getLevelFours: function(level) { 
    let theUrl = this.computeCompleteUrl(level); 
    // http request based on url 
    var xmlHttp = new XMLHttpRequest(); 
    xmlHttp.open("GET", theUrl, false); // false for synchronous request 
    xmlHttp.send(null); 
    var myjson = JSON.parse(xmlHttp.responseText) 
    return myjson.l4byl2; 
相关问题