我试图理解这个关于这个概念的帖子,但是,我没有得到它.我有以下简单的设置:
/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);
Run Code Online (Sandbox Code Playgroud)
此结构返回到控制台undefined.
如果我将myapp.js文件更改为:
Meteor.call('abc', function(err, data) {
!err ? console.log(data) : console.log(err);
}
Run Code Online (Sandbox Code Playgroud)
我收到了Object我的控制台.
理想情况下,这是我希望能够做到的,但它不起作用,在控制台中说明: Cannot read property 'greeting' of undefined
/client/myapp.js
var q = Meteor.call('abc');
Template.hello.greeting = function() {
return q.foo;
}
Run Code Online (Sandbox Code Playgroud)
将数据从服务器对象传递到模板的任何帮助将不胜感激.我还在学习JavaScript和Meteor.
谢谢!