-使用流星框架--
嗨,我想通过Template["tViewPost"]访问下面的模板
<template name="tViewPost">
<div class="breadcrumb">
<span>{{title}}</span>‹‹<span>{{subttile}}</span>
</div>
</template>并且能够使用像{ title : "My title", subttitle : "othe subtitle"};这样的javascript对象来呈现/评估这个模板,但是我不知道如何实现它,一旦我在变量中有了模板,我想要像下划线库那样做。
var template = _.template("whatever <%= title %>");
var o = {title : "ohhh!"};
$("someDomElement").html(template(o))这样做有可能吗?怎么做呢?谢谢..。
发布于 2013-11-19 07:52:40
您可以使用Meteor.render (来自docs)尝试这样做:
// 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}});编辑:
// 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)))https://stackoverflow.com/questions/20064748
复制相似问题