【发布时间】:2012-05-27 11:53:32
【问题描述】:
我已经尝试过to understand this post regarding this concept,但是我没有得到它。我有以下简单的设置:
/server/test.js
Meteor.methods({
abc: function() {
var result = {};
result.foo = "Hello ";
result.bar = "World!";
return result;
}
});
/client/myapp.js
var q = Meteor.call('abc');
console.log(q);
这个结构返回到控制台undefined。
如果我将myapp.js 文件更改为:
Meteor.call('abc', function(err, data) {
!err ? console.log(data) : console.log(err);
}
我在控制台中收到Object。
理想情况下,这是我想做的,但它不起作用,在控制台中说明:Cannot read property 'greeting' of undefined
/client/myapp.js
var q = Meteor.call('abc');
Template.hello.greeting = function() {
return q.foo;
}
在将数据从服务器对象传递到模板中的任何帮助将不胜感激。我还在学习 JavaScript 和 Meteor。
谢谢!
【问题讨论】: