【问题标题】:Partials in mustache.jsmustache.js 中的部分
【发布时间】:2015-01-06 21:10:53
【问题描述】:

我试图弄清楚 mustache 中的部分是如何工作的。

JS

var mustacheTmpl = Mustache.render(popups, {list:true});

弹出模板

{{#list}}
<ul class="pending-job-list">
<li>test</li>
</ul>
{{/list}}

现在我想把他的列表放在同一个模板(弹出窗口)的一些标记中并渲染它

{{#outer}}
   <div class="outerPopup">
      // I want to render the list inside here
   </div>
{{/outer}}

我如何做到这一点?

【问题讨论】:

    标签: mustache partials


    【解决方案1】:

    你在这里:

    var partial = "{{#list}}"+
    "<ul class=\"pending-job-list\">"+
    "<li>{{.}}</li>"+
    "</ul>"+
    "{{/list}}";
    
    
    var template = "{{#outer}}"+
    "<div class=\"outerPopup\">"+
    "{{>list}}"+
    "</div>"+
    "{{/outer}}";
    
    var html = Mustache.render(template, { outer: {list:["test"]} }, { list:partial });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-03
      • 2012-12-03
      • 2023-04-05
      • 1970-01-01
      • 2011-05-22
      相关资源
      最近更新 更多