我有一条路线,想要返回该路线的数据需要来自对服务器的 AJAX REST 请求,该请求的响应应用作模板数据,以便我可以循环遍历结果模板。
实现这一目标的最简单方法是什么?我需要将其作为传递到模板的数据函数内的同步调用。像这样:
Router.map(function() {
this.route('test', {
path: '/test',
data: function() {
var templateData = { title : 'My Redeemed Rewards', menu : 'ion-navicon', parent : 'myRewards' }
// Make syncronous request and extend the template data object with the json response
return templateData;
}
});
});
或者将其设置为异步请求,并在数据可用时重新呈现模板。在这种情况下我如何让模板重绘?
最佳答案
您可以通过传递 null
作为名称来创建内存集合。
http://docs.meteor.com/#/full/collections
new Mongo.Collection(名称, [选项])
name String The name of the collection. If
null
, creates an unmanaged (unsynchronized) local collection.
创建可由客户端调用的方法。
http://docs.meteor.com/#/full/meteor_methods
该方法将通过 REST 从其他服务器加载数据并将其放入
进入本地收藏。
关于javascript - Meteor AJAX 请求模板数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26905866/