【问题标题】:How to deal with many templates in knockout?如何处理淘汰赛中的许多模板?
【发布时间】:2014-04-13 01:28:57
【问题描述】:

在处理淘汰赛时,我经常使用templates。因为我正在开发单页应用程序,所以我使用的模板数量越来越多。

我的主要 html 开始看起来像这样:

<!-- id's for knockout binding -->
<span id='...'>...</span>
<span id='...'>...</span>
....
<span id='...'>...</span>

<!-- templates -->
<script type="text/html" id="template_1">...</script>
<script type="text/html" id="template_2">...</script>
...
<script type="text/html" id="template_100">...</script>

尽管如此,一切都按预期工作,我被大量模板吓倒了,一开始就被加载。

那么在这个问题上是否有任何最佳实践,或者在淘汰赛方面有良好经验的人如何处理它?

【问题讨论】:

    标签: knockout.js knockout-templating knockout-3.0


    【解决方案1】:

    最好使用外部模板,而不是将所有模板放在一个文件中。通过使用外部模板,您可以按需调用它们,而不是一次加载所有模板。因此,外部模板有很多可用的选项。欲了解更多信息,请查看External Templates

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 2011-08-11
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2012-07-16
      • 2016-07-18
      • 1970-01-01
      相关资源
      最近更新 更多