【发布时间】:2015-06-16 12:25:41
【问题描述】:
只是想在 Meteor JS 中解决问题。我一直试图将 Meteor.call 结果对象传回模板。这是我的代码:
HTML 模板
<template name="showTotals">
<div class="container">
{{#each recordCnt}}
{{/each}}
</div>
</template>
客户端 JS
//get a count per item
Template.showTotals.recordCnt = function(){
Meteor.call('getCounts', function(err, result) {
if (result) {
//console.log(result); <-this shows object in javascript console
return result;
}
else {
console.log("blaaaa");
}
});
}
服务器 JS
Meteor.startup(function () {
Meteor.methods({
getCounts: function() {
var pipeline = [{$group: {_id: null, count: {$sum : 1}}}];
count_results = MyCollection.aggregate(pipeline);
return count_results;
}
});
});
全球 JS
MyCollection = new Meteor.Collection('folks');
我已尝试为调用结果添加一个 console.log(result),它会显示在 javascript 控制台中并显示预期结果。但是,我无法让它填充 recordCnt。
有什么想法吗?
【问题讨论】:
标签: templates object meteor callback server