[英]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. Iron-ajax请求后,使用javascript添加数据。 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. 一切都可以正常工作,除了一件事:当我使用dom-repeat绑定添加的数据时,我使用
<dom-if>
模板,因为根据列的类型,我必须访问并显示相应的信息。 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. 所以我的问题是我无法正确显示信息,我认为原因是使用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. 信息不在表格中,我正在检查
getType
函数,但我认为还可以。 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.
要解决此问题,必须在Polymer.html文件中更改两个功能。 The functions are
_wrapTextNodes
and _showHideChildren
. 这些功能是
_wrapTextNodes
和_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;
}
}
}
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.