【问题标题】:Show images from links in Underscore templates (especially from dropbox image links)显示来自下划线模板中链接的图像(尤其是来自 Dropbox 图像链接)
【发布时间】:2012-10-24 20:07:28
【问题描述】:

如何在下划线模板中插入图片链接,以便显示图片?

【问题讨论】:

  • 有什么<img src="..."> 不适合你吗?

标签: javascript jquery jquery-mobile backbone.js underscore.js


【解决方案1】:
script type="text/template" class="imageViewTemplate">
      <img src=<%=imageUrl%> />
</script>

然后您必须解释模板,将 url 传递给已编译的模板。例如,如果您使用主干,您将在主干视图渲染函数中执行如下操作。

render(){
      var compiledTemplate = _.template($("#imageViewTemplate").text()));
      var interpretedImageTemplate = compiledTemplate({url: "url to image service"});
      $(this.el).append( interpretedImageTemplate );
}

这只是为了展示我们如何插入图片链接的肮脏示例。最好有一个抽象类,它接受模板和模型,然后可以重用。

【讨论】:

    猜你喜欢
    • 2019-09-22
    • 2011-07-02
    • 2012-12-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多