Knockout.js无容器的"foreach"不能与< table>一起使用 [英] Knockout.js containerless "foreach" not working with <table>

查看:81
本文介绍了Knockout.js无容器的"foreach"不能与< table>一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码引发错误(在Chrome中):找不到匹配的结束注释标记:ko foreach:MyPlans":

This code throws the error (in Chrome): "Cannot find closing comment tag to match: ko foreach: MyPlans":

<table>
  <!-- ko foreach: MyPlans -->
    <tr>
      <td>Test</td>
    </tr>
  <!-- /ko -->
</table>

如果我改用列表,则一切正常:

If I use a list instead, everything works:

<ul>
  <!-- ko foreach: MyPlans -->
    <li>
      Test
    </li>
  <!-- /ko -->
</ul>

我想将无容器的foreach与表一起使用.我做错什么了吗?是虫子吗?

I would like to use the containerless foreach with a table. Is there something I'm doing wrong? Is it a bug?

推荐答案

这与浏览器自动插入tbody标签有关,这会导致注释不匹配.呈现的输出将如下所示:

This is related to the fact that browsers insert tbody tags automatically, which creates a mismatch in the comments. The rendered output will look like:

<table>
  <!-- ko foreach: MyPlans -->
  <tbody>
    <tr>
      <td>Test</td>
    </tr>
  <!-- /ko -->
  </tbody>
</table>

Steve确实做了一些工作来尝试纠正KO中不匹配的标签,但是最简单的操作是您自己添加tbody或添加tbody并对其进行绑定.

Steve did put some work into trying to correct mismatched tags in KO, but the easiest thing for you to do is either add the tbody yourself or add the tbody and put your binding on it.

<table>
  <tbody data-bind="foreach: MyPlans">
    <tr>
      <td>Test</td>
    </tr>
  </tbody>
</table>

如果有必要,一个表具有多个tbody标记是合法的.

It is legal for a table to have multiple tbody tags, if necessary.

这篇关于Knockout.js无容器的"foreach"不能与&lt; table&gt;一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆