简体   繁体   English

聚合物铁单迭代,但不打印

[英]Polymer iron-list iterates, but not printing

I'm trying to use an iron-list in Polymer to display an array of object as a list. 我正在尝试在Polymer中使用铁列表来将对象数组显示为列表。 Inside the polymer function, I have ... 在聚合物功能内部,我有...

ready: function() {
    this.list = [{title: 'Thing 1'}, {title: 'Thing 2'}, {title: 'Thing 3'}];
}

and in the template, I have ... 在模板中,我有...

<iron-list items="[[ list ]]" as="l">
    <template>
        <div class="row">
            <div class="" on-tap="">
                <span>[[ l.title ]]</span>
                <paper-checkbox class="right"></paper-checkbox>
            </div>
        </div>
    </template>
</iron-list>

I imported "iron-list.html" into the file. 我将“ iron-list.html”导入到文件中。

What I'm seeing, is that the iron-list creates 3 templates (rightly so), but it doesn't print out the strings (the titles). 我所看到的是,铁清单创建了3个模板(正确的是),但是它没有打印出字符串(标题)。 This should've been simple but I'm lost here. 这应该很简单,但是我在这里迷路了。 Anyone has any idea why it doesn't print out? 任何人都知道为什么它不打印出来吗?

EDIT: One important thing I left out is that this element started out with display: none and then toggled to show later on. 编辑:我遗漏的一件事是该元素以display: none开始display: none ,然后切换为稍后显示。

From here , it says 这里

iron-list lays out the items when it recives a notification via the resize event. Iron-List通过resize事件接收通知时,将对项目进行布局。 This event is fired by any element that implements IronResizableBehavior. 任何实现IronResizableBehavior的元素都会触发此事件。

By default, elements such as iron-pages, paper-tabs or paper-dialog will trigger this event automatically. 默认情况下,铁页,纸张标签或纸张对话框之类的元素将自动触发此事件。 If you hide the list manually (eg you use display: none) you might want to implement IronResizableBehavior or fire this event manually right after the list became visible again. 如果您手动隐藏列表(例如,使用display:none),则可能要实现IronResizableBehavior或在列表再次可见后立即手动触发此事件。 eg 例如

So you will need to manually call 因此,您需要手动致电

document.querySelector('iron-list').fire('resize');

after the list is shown. 显示列表之后。


Also, even if you didn't hide/show the list, your code still wouldn't work 'cause you assigned the value to the list a bit too early. 另外,即使您没有隐藏/显示列表,您的代码仍然无法正常工作,因为您为list分配值的时间太早了。

The reason is that inside iron-list , the function that does the rendering _render will only do the job when this._isVisible is true . 其原因是,里面iron-list ,但这渲染功能_render只会做这个工作的时候this._isVisibletrue And this._isVisible is based on the sizing ( offsetWidth & offsetHeight ) of the iron-list itself. 并且this._isVisible基于iron-list本身的大小( offsetWidthoffsetHeight )。

So instead, try assigning the value inside the attached handler, with a little delay when needed - 因此,请尝试在attached处理程序中分配值,并在需要时稍作延迟-

attached: function () {
    this.async(function () {
        this.list = [{ title: 'Thing 1' }, { title: 'Thing 2' }, { title: 'Thing 3' }];
    }, 100);
}

I'm pretty sure you did not declare an explicit size for your iron-list element. 我很确定您没有为铁表元素声明显式尺寸。

From the docs : 文档

Important : iron-list must ether be explicitly sized, or delegate scrolling to an explicitly sized parent. 重要提示 :Iron-List必须以太大小明确,或委托滚动到以明确大小大小的父对象。 By "explicitly sized", we mean it either has an explicit CSS height property set via a class or inline style, or else is sized by other layout means (eg the flex or fit classes). “显式调整大小”是指它要么通过类或内联样式设置了显式的CSS height属性,要么通过其他布局方式(例如flex或fit类)进行调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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