简体   繁体   中英

dom-if issue in polymer?

I have an table element where the declaration is as follows

    <euro-table id="euroTable" number-visible-rows="10">
        <euro-column title="Id" type="text" key="Id"></euro-column>
        <euro-column title="Descripcion" type="text" key="Descripcion"></euro-column>
        <euro-column title="Abreviatura" type="text" key="ShortName"></euro-column>
        <euro-column title="Tipo" type="object" key="FeeType" objectkey="Descripcion"></euro-column>
        <euro-column title="Monto($)" type="text" key="Monto"></euro-column>
        <euro-column title="Cobrar a" type="array" key="NivelesEscolares" objectkey="Descripcion"></euro-column>
    </euro-table>

Data is added using javascript after an iron-ajax request. Everything works as it should work, except for one thing: when I use dom-repeat to bind added data I use <dom-if> template because depending on the type of column, I must access and display the corresponding information. The code I use to do that is the following:

<template is="dom-repeat" items="{{visibleRows}}" id="tableRow" as="row">
    <tr on-tap="rowSelected" class$="{{getClass(item.active)}}">
        <template is="dom-repeat" items="{{headers}}" id="tableRow2" as="column">
            <template is="dom-if" if="{{getType(column.type, 'object')}}">
                <td>
                    <li>{{getObjectValue(column,row)}}</li>
                 </td>
             </template>
             <template is="dom-if" if="{{getType(column.type, 'array')}}">
                  <td>
                      <template is="dom-repeat" items="{{getDataArray(column,row)}}">
                          <li>{{getObjectValue(column,row)}}</li>
                       </template>
                  </td>
              </template>
              <template is="dom-if" if="{{getType(column.type, 'text')}}">
                  <td>{{getValue(column,row)}}</td>
              </template>
        </template>
      </tr>
 </template>

So my problem is that I can not display the information correctly and I think the reason is for the use of dom-repeat. My information is displayed as follows: 在此处输入图片说明

The information is out of the table, I'm a checking my getType function but I think its ok. Any idea about to fix my bug? Thanks!

After I had researched a little more, I found here that my problem was a bug of polymer. To solve it, is necessary to change two functions in Polymer.html file. The functions are _wrapTextNodes and _showHideChildren . I will leave the functions here just in case anyone have the same problem.

_wrapTextNodes: function(root) {
  // wrap text nodes in span so they can be hidden.
  for (var n = root.firstChild; n; n=n.nextSibling) {
    if (n.nodeType === Node.TEXT_NODE && n.textContent.trim.length) {
      var s = document.createElement('span');
      root.insertBefore(s, n);
      s.appendChild(n);
      n = s;
    }
  }
},
_showHideChildren: function() {
  var hidden = this._hideTemplateChildren || !this.if;
  if (this._instance) {
    var c$ = this._instance._children;
    for (var i=0; i<c$.length; i++) {
      var c = c$[i];
      if (c.nodeType !== Node.TEXT_NODE) {
        c.style.display = hidden ? 'none' : '';
        c._hideTemplateChildren = hidden;
      }
    }
  }
},

Here you can find dom-if.html file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM