<template iterate ="...">和<template repeat ="...">之间的区别

Mat*_*rog 4 dart

我已经看过一些Dart示例/教程看起来像<template iterate="thing in collection">和其他使用的<template repeat="thing in collection">.他们似乎完全一样.他们之间有什么区别,为什么在特定情况下推荐一个而不是另一个?

Zde*_*vic 10

这里直接来自更改日志:

添加了'template-repeat',与模板迭代不同,如果用作属性,它会重复标记而不是标记的子代.

原因是以下HTML对大多数HTML解析器无效:

<select>
  <template iterate='name in results'>
    <option>{{name}}</option>
  </template>
</select>`
Run Code Online (Sandbox Code Playgroud)

template标签是不允许的select,所以解决方案是使用:

<select>
  <option template repeat='name in results'>{{name}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)

template repeat最近被添加(2013年4月),它template iterate最终将取代AFAIK,但目前两者都得到支持.