【问题标题】:How to compile a template from a string?如何从字符串编译模板?
【发布时间】:2013-06-26 20:40:35
【问题描述】:

如何从字符串编译模板?
示例:

s = "您好 {{#each users}} {{FirstName}}, {{/each}}"

你需要得到:

s = "你好用户1,用户2,用户3,

【问题讨论】:

  • 你到底想完成什么?
  • MongoDB页面模板中有一条记录,变量形式为{{variable}},循环如{{# each}} {{/ each}}。你想显示这个模式的 MongoDB 并编译。

标签: meteor handlebars.js


【解决方案1】:

我不确定我是否理解您想要做什么。也许是这样:

把它放在一个 .html 文件中:

<template name="someTemplate">

   Hello {{#each users}} {{FirstName}}, {{/each}}

</template>

把它放在一个 .js 文件中:

if (Meteor.isClient) {

   Template.someTemplate.helpers({
      users: function() {
         // "Users" is a Meteor Collection
         return Users.find({});
      }
   });

}

【讨论】:

  • 找到了类似的东西,不过这个模板要指定事件和变量..
  • var tmpl = Meteor._def_template("templateName", function () { return "some html string"; });
  • 对不起,我不明白你想要完成什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-23
  • 2016-12-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-09
相关资源
最近更新 更多