【问题标题】:Backbone: rendering dynamic content in jst.ejs filesBackbone:在 jst.ejs 文件中渲染动态内容
【发布时间】:2012-09-13 12:29:26
【问题描述】:

我正在关注 Rails 的 Ryan Bates 主干.js 教程。他使用 jst.eco 模板。但是,我使用的是 jst.ejs 文件。

他的视图创建了一些他想插入到模板中的内容,即“Entries go here”

$(this.el).html(this.template(entries: "Entries go here"));
 return this;

它会被插入到模板中的<%= @entries %>

<h1>App Name</h1>

<%= @entries %>

我正在使用 index.jst.ejs 文件执行此操作,但它不起作用。

首先。有谁知道我应该在模板中使用哪些标签来呈现动态内容?

其次,在template()括号内做entries: "Entries go here"是否仍然正确,如

$(this.el).html(this.template({entries: "Entries go here"}));

注意,我没有使用咖啡脚本

【问题讨论】:

    标签: backbone.js ejs


    【解决方案1】:

    模板中的“条目”前面不需要@ 或“this”。

    视图/条目/索引

     render: function(){
    
        $(this.el).html(this.template({
    
            entries: "Entries go here"
    
        }));
        return this;
      }
    

    模板/条目/index.jst.ejs

    <%= entries %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      相关资源
      最近更新 更多