基本上这是我的代码而且重复了。如果我使用have_last_attr
2次(内部if),它不起作用。我怎么能管理它?
# .html
{{#if have_last_attr}}
<h3>Last attribute was {{last_attr}}</h3>
{{/if}}
# .js
Template.game.have_last_attr = function(){
var game_id = Session.get('current_game'),
game = Games.findOne(game_id),
attr = game['last_attr'];
return TRANSLATE[attr];
};
Template.game.last_attr = function(){
var game_id = Session.get('current_game'),
game = Games.findOne(game_id),
attr = game['last_attr'];
return TRANSLATE[attr];
};
提前致谢
答案 0 :(得分:1)
您可以使用{{#with ...}}
声明(handlebars doc)。如果我不想做两次事情,至少这就是我所做的......
{{#with last_attr}}
{{#if this}}
<h3>Last attribute was {{this}}</h3>
{{/if}}
{{/with}}