【发布时间】:2014-11-12 04:47:17
【问题描述】:
我被困住了,所以非常感谢任何帮助。我已经尝试了很多东西 - 对流星来说是新手,但无法让模板中的 #each 显示任何内容
查看我的流星垫http://meteorpad.com/pad/FqMJWySAMZGcyaTf6 或查看下面的代码。
<template name="player">
<div>{{_id}}</div>
<div class="name">{{name}}</div>
<div class="score">{{score}}</div>
<div>{{>cards hand}}</div>
</template>
<template name="cards">
<div>
{{#each hand}}
<span>{{this}}</span>
{{/each}}
</div>
</template>
在客户端 - 响应在下面的 console.log 中正确显示:
Template.cards.hand = function(){
if (Players.find().count() > 0 )
{
Meteor.call("deal", playerNum,function(err,response){
if(err){
console.log("error dealing: " + err);
}
console.log("in player hand" + response);
return response;
});
}
};
【问题讨论】:
-
从哪里获得 playerNum?
-
客户端上的
Meteor.call在内部实现为AJAX操作,这就是为什么它需要回调function(err,response)以便稍后在操作完成时调用。但这不会向Template.cards.hand()返回任何内容,因为操作只是排队,Template.cards.hand()将立即返回,没有数据。 -
@Paul 异步,但不是 AJAX。 Meteor 方法调用使用 DDP(就像订阅一样)。
-
@Neil Fine,但有类似的限制。