简体   繁体   English

在表格标签中使用模板中继器

[英]Using a Template Repeater in a Table tag

In my application I have noticed that my template repeater does not get called when inside of a table. 在我的应用程序中,我注意到在表中时未调用模板中继器。 My goal is to use the repeater to complete the data and refresh it as needed. 我的目标是使用转发器来完成数据并根据需要刷新。

Markup: 标记:

<table>
    <tr>
        <th>Name</th>
        <th>Date Uploaded</th>
        <th>Default</th>
    </tr>
    <template id="themesRows" is="dom-repeat" items="{{themeList}}">
        <tr>
            <td>TEST {{item.name}}</td>
            <td>{{item.dateCreatedUtc}}</td>
            <td>
                <!--<input type="radio" name="default" value="{{item.id}}" selected="{{item.id == model.defaultThemeId}}" />-->
            </td>
            <td>{{index}}</td>
        </tr>
    </template>
</table>

Dart: 镖:

class SampleB {
  String name = "";
  String dateCreatedUtc = "";
  int id = 0;
  SampleB(this.id, this.name, this.dateCreatedUtc);
}

class MyPolymerElement extends PolymerElement{ @property List themeList = []; 类MyPolymerElement扩展PolymerElement {@property List themeList = []; MyPolymerElement.created() : super.created(); MyPolymerElement.created():super.created(); attached(){} } Attached(){}}

This is not necessarily something "broken" in Polymer or your code, rather it is a limitation caused by a "feature" in the browser parser. 这不一定是Polymer或代码中的“损坏”,而是由浏览器解析器中的“功能”引起的限制。 Since the element hierarchy for table is well defined, browsers have specific parsing rules when they process them. 由于table的元素层次结构定义明确,因此浏览器在处理它们时具有特定的解析规则。 When drilling into a table hierarchy, if the parser comes across a child it does not expect, it produces unexpected results. 深入table层次结构时,如果解析器遇到了它不期望的子级,则会产生意外的结果。

It's hard to tell from the excerpt, but I would guess that your repeater is actually working, but the browser is not rendering the rows within the table. 从摘录中很难分辨出来,但我想您的中继器实际上正在工作,但是浏览器未在表中呈现行。 If you want to post a complete demo of the issue, I'd be happy to review and amend my answer. 如果您想发布该问题的完整演示,我们很乐意查看并修改答案。

A way around this is to just put an observer on your themeList property. 一种解决方法是将观察者放在您的themeList属性上。 When the value changes, use DOM manipulation to fill or modify the table. 当值更改时,请使用DOM操作来填充或修改表。


There is some good information about it in the discussion related to this issue: https://github.com/Polymer/polymer/issues/4135 在与此问题相关的讨论中,有一些很好的信息: https : //github.com/Polymer/polymer/issues/4135

Per the thread, it appears there is a fix that will allow this in the Polymer 2.0 preview release. 对于每个线程,似乎都存在一个修复程序,该修复程序将在Polymer 2.0预览版本中允许此操作。

When looking at design methodologies of Polymer being a modern version of HTML, coupled with Dart (originally tagged as the future of web programming). 在查看Polymer的设计方法时,它是HTML的现代版本,并与Dart结合使用(最初标记为Web编程的未来)。 I had to do some sample tests. 我必须做一些样本测试。 After extracting it to its own spot, outside that of the table I did confirm that the data does in fact, repeat. 将其提取到自己的位置之后,在表格之外,我确实确认数据确实重复了。 The issue comes from the table. 问题出在表上。

A table is an old way of listing out data. 表是列出数据的一种旧方法。 It is the oldest but one of the most used concepts on the internet. 它是互联网上最古老但使用最广泛的概念之一。 With this new age of computing and the leveraging of Design methodologies of Polymer we aren't actually suppose to use them at all. 随着计算的新时代和Polymer设计方法的利用,我们实际上根本不打算使用它们。

Conceptually, there are more modern and entertaining ways to display information to users. 从概念上讲,有更多现代且有趣的方式可以向用户显示信息。 One of the most commonplace concepts is the idea all throughout Polymer, Cards. 最普遍的概念之一是贯穿Polymer,Cards的整个想法。 You would define a card through css and html and repeat that, creating so many of the lists around the polymer websites. 您将通过css和html定义卡,然后重复该操作,从而在聚合物网站周围创建了很多列表。

I thought long and hard about this. 我为此想了很久。 It seems that putting a template repeater inside of a table and a table>tbody pair would not carry out the render, instead it just rendered it as is. 似乎将模板转发器放在表和table> tbody对中不会执行渲染,而是仅按原样进行渲染。 1 row of empty strings underneath the header concepts. 标头概念下的1行空字符串。

So to get the correct answer to your explicit question, you could do something like this. 因此,要获得对您的明确问题的正确答案,您可以执行以下操作。

<dom-module id="tableDesign">
  <template>
    <style>
      .table { display: table;}
      .row { display: table-row;}
      .header { font-weight:bold; display: table-cell; text-align:center;}
      .cell { display: table-cell;}
    </style>

    <div class="table">
      <div class="row">
        <div class="header">Name</div>
        <div class="header">Date Created</div>
        <div class="header">Default</div>
      </div>
      <template is="dom-repeat" items="{{themeList}}">
        <div class="row">
          <div class="cell">{{item.name}}</div>
          <div class="cell">{{item.dateCreatedUtc}}</div>
          <div class="cell">
            <!-- Insert Radio Here -->
          </div>
        </div>
      </template>
    </div>
  </template>
</dom-module>

This will get your repeater to work, while leveraging a "table" without using the table tag. 这将使您的中继器正常工作,同时利用“表格”而不使用table标签。

On a deeper level of understanding though, I think that looking at a more modern concept for displaying your rows of data should be looked into. 但是,从更深层次的理解来看,我认为应该研究一种更现代的概念来显示数据行。 Developing a card or structure which fits with the modern concepts would allow you to effectively lever the modern tools you are trying to use. 开发适合现代概念的卡片或结构可以使您有效地利用要使用的现代工具。

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

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