首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态评估模板

动态评估模板
EN

Stack Overflow用户
提问于 2013-11-19 06:32:49
回答 1查看 131关注 0票数 0

-使用流星框架--

嗨,我想通过Template["tViewPost"]访问下面的模板

代码语言:javascript
复制
<template name="tViewPost">
    <div class="breadcrumb">
        <span>{{title}}</span>&lsaquo;&lsaquo;<span>{{subttile}}</span>
    </div>
</template>

并且能够使用像{ title : "My title", subttitle : "othe subtitle"};这样的javascript对象来呈现/评估这个模板,但是我不知道如何实现它,一旦我在变量中有了模板,我想要像下划线库那样做。

代码语言:javascript
复制
var template = _.template("whatever <%= title %>");
var o = {title : "ohhh!"};
$("someDomElement").html(template(o))

这样做有可能吗?怎么做呢?谢谢..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-19 07:52:40

您可以使用Meteor.render (来自docs)尝试这样做:

代码语言:javascript
复制
// Client side: show the number of players online.
var frag = Meteor.render(function () {
  return "<p>There are " + Players.find({online: true}).count() +
    " players online.</p>";
});
document.body.appendChild(frag);

// Server side: find all players that have been idle for a while,
// and mark them as offline. The count on the screen will
// automatically update on all clients.
Players.update({idleTime: {$gt: 30}}, {$set: {online: false}});

编辑:

代码语言:javascript
复制
// returns string which contains html
Meteor.render(Template['name'](dataObject))


// your case:
<template name="test">
   whatever {{title}}"
</template>

var o = {title : "ohhh!"};

$("someDomElement").html(Meteor.render(Template['test'](o)))
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20064748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档