Knockout.js containerless “foreach” not working with
前端 未结 1 2056
南方客
南方客 2020-11-27 19:27

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

相关标签:
1条回答
  • 2020-11-27 20:03

    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 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>
    

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

    0 讨论(0)
提交回复
热议问题