Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态评估模板_Javascript_Meteor - Fatal编程技术网

Javascript 动态评估模板

Javascript 动态评估模板,javascript,meteor,Javascript,Meteor,--使用METEOR框架-- 您好,我想通过template[“tViewPost”] 有可能吗?怎么做?谢谢 您可以尝试使用(从文档中)执行此操作: //客户端:显示在线玩家的数量。 var frag=Meteor.render(函数(){ 返回“有”+个玩家。查找({online:true}).count()+ “在线玩家。”; }); 文件.正文.附件(frag); //服务器端:查找所有空闲一段时间的玩家, //并将其标记为脱机。屏幕上的计数将显示 //在所有客户端上自动更新。 更新({

--使用METEOR框架--

您好,我想通过
template[“tViewPost”]


有可能吗?怎么做?谢谢

您可以尝试使用(从文档中)执行此操作:

//客户端:显示在线玩家的数量。
var frag=Meteor.render(函数(){
返回“有”+个玩家。查找({online:true}).count()+
“在线玩家。

”; }); 文件.正文.附件(frag); //服务器端:查找所有空闲一段时间的玩家, //并将其标记为脱机。屏幕上的计数将显示 //在所有客户端上自动更新。 更新({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)))
//返回包含html的字符串
render(模板['name'](数据对象))
//你的情况:
无论什么{{title}}”
var o={title:“ohhh!”};
$(“somedoElement”).html(Meteor.render(模板['test'](o)))

嗯,这个问题对我来说并不清楚。1.你不知道如何为变量分配字符串文字吗?或者模板代码存在于某个文件中,你希望能够在服务器上读取该文件并将其传递给客户端的javascript?2.你想使用下划线的模板函数还是编写自己的模板函数?嗨,伙计正在使用Meteor框架,Meteor有一个名为Template的全局变量,该变量保存您在任何html文件中声明的所有模板,然后您可以通过模板[“模板名称”]访问模板功能。我的问题是如何使用这个很棒的系统,但使用下划线。我计划不久学习Meteor,而不是Meteor使用的模板系统handlerbars.js。因此,我一直在网上阅读文档、观看屏幕广播等。我相信,到目前为止,下划线是与Meteor一起打包的。因此,您应该能够直接使用underline.js中的方法,只需像编写普通underline.js应用程序那样编写模板。我已经尝试过了,但实际上问题是,我尝试模拟下划线的方式有点不同。在字符串上。动态使用对象对其进行评估。使用示例更新帖子类似于下划线1。哦,谢谢你,我会在几分钟内尝试……如果工作顺利,你肯定会得到正确的答案:D
var template = _.template("whatever <%= title %>");
var o = {title : "ohhh!"};
$("someDomElement").html(template(o))
// 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)))