Meteor-通过ajax返回HTML模板
我想在另一个网站上显示在我的Meteor应用程序中生成的模板 我曾希望在网站中使用ajax调用来获取相关的meteor模板和数据,但我现在很挣扎 该网站的呼吁如下:Meteor-通过ajax返回HTML模板,ajax,api,templates,meteor,handlebars.js,Ajax,Api,Templates,Meteor,Handlebars.js,我想在另一个网站上显示在我的Meteor应用程序中生成的模板 我曾希望在网站中使用ajax调用来获取相关的meteor模板和数据,但我现在很挣扎 该网站的呼吁如下: <body> <div id="result"> </div> </body> <script> $( "#result" ).load( "http://myMeteorApp/get_template" ); </script> 模板“get_t
<body>
<div id="result">
</div>
</body>
<script>
$( "#result" ).load( "http://myMeteorApp/get_template" );
</script>
模板“get_template.html”位于“private”文件夹中
<template name="get_template">
<table class="table table-hover table-condensed">
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
</tr>
{{#each members}}
<tr>
<td>{{first_name}} {{last_name}}</td>
<td>{{email}}</td>
<td>{{mobile}}</td>
</tr>
{{/each}}
</table>
名称
电子邮件
可移动的
{{#每个成员}
{{first_name}{{last_name}}
{{email}}
{{mobile}}
{{/每个}}
这不起作用,我觉得我找错了方向
也许我应该用iframe?但我更喜欢Meteor应用程序像API一样运行,只返回模板
感谢您的帮助。:
服务器操作函数(RouteControl)具有不同的属性
以及可用的方法。也就是说,服务器上没有渲染
然而
此外,即使这样做有效,您的javascript中也缺少很多内容:
- 您似乎没有指定要在模板中使用的数据的任何位置
- action函数返回一个字符串。这是怎么回事
Router.map(函数(){
此.route('serverFile'{
其中:'服务器',
路径:'/get_template/:templatename',
行动:功能(){
var templatename=this.params.templatename;
this.response.writeHead(200,{'Content-Type':'text/html'});
end(handlebar.templates[templatename]({members:[]}));
}
});
});
将数据插入所提供对象的
members
字段。Yep,所以RTFM!我想知道iron router的1.0和新分支是否会包括服务器端路由?
<template name="get_template">
<table class="table table-hover table-condensed">
<tr>
<th>Name</th>
<th>Email</th>
<th>Mobile</th>
</tr>
{{#each members}}
<tr>
<td>{{first_name}} {{last_name}}</td>
<td>{{email}}</td>
<td>{{mobile}}</td>
</tr>
{{/each}}
</table>