Ember.js查看/渲染/部分/模板?

时间:2014-02-14 11:43:22

标签: ember.js

我正在使用fixtureadapter并拥有以下模型:

user (id, name, hasMany:poll)
poll (id, question, belongsTo:user, hasMany:item)
item (id, text, votes, belongsTo:poll)

在把手文件中有这样的东西的最佳方法是什么:

  

{{poll user = 1}}或{{poll id = 32}}

这将呈现(用户的最新民意调查或)带有问题文本+项目的民意调查。

"What is the best js framework?"
 - ember.js
 - angular.js
 - other
"question by: username"

1 个答案:

答案 0 :(得分:3)

您可以在ember中使用'render'帮助器并将模型传递给它。

{{render 'pollWithQuestions' poll}}

这将呈现名为“PollWithQuestions”的模板,控制器和视图,并使用您传入的轮询模型。

我会让PollWithQuestionsController处理逻辑,以确定是否应该为用户显示最新的轮询,如果这是您通过的而不是实际的轮询。您永远不应该在模板中处理这种逻辑,这是把手不支持它的主要原因。

供参考:http://emberjs.com/guides/templates/rendering-with-helpers/

相关问题