【问题标题】:How to load HTML template file content from JavaScript如何从 JavaScript 加载 HTML 模板文件内容
【发布时间】:2017-01-24 16:16:23
【问题描述】:

我有一个 collection,其中包含一个 tab 模型数组

喜欢

[
  new TabModel({ title: 'Step 1', template: 'step1.html' }),
  new TabModel({ title: 'Step 2', template: 'step2.html' }),
  new TabModel({ title: 'Step 3', template: 'step3.html' }),
  new TabModel({ title: 'Step 4', template: 'step4.html' })
]

在我的View 循环collection 中,我得到了标题和template,它位于templates 文件夹下。

View中获取模板内容的方法是什么

【问题讨论】:

标签: javascript backbone.js


【解决方案1】:

有很多方法可以做到这一点。如果您的主干设置最少,您可以使用 jQuery load 方法来检索 HTML 内容。

如果您使用的是 RequireJS,那么它有一个文本插件,也有一些 webpack 模块可以做到这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 2019-12-19
    • 2020-02-29
    • 2010-10-24
    • 2021-01-08
    • 1970-01-01
    相关资源
    最近更新 更多