我在控制器上有一个属性,我们将其称为showTheStuff
,并且我的模板中有一个{{#each}}
帮助器。现在,我只是明确地设置属性。Ember:从每个帮手中访问控制器属性
在该列表中,我想根据showTheStuff
的值有条件地呈现或不呈现某些标记,但如果使用{{#unless}}条件,则不起作用。
http://emberjs.jsbin.com/jarapabela/1/
我如何得到这个工作? 在我的代码中,它不能与{{#unless}}一起使用,但如果我切换属性并使用{{#if}},它确实有效。有没有其他人经历过这个?
我正在使用Ember 1.6。
控制器:
export default Ember.ArrayController.extend({
hideDeleteButton: true,
actions: {
deleteComment: function(comment) {
comment.destroyRecord();
this.removeObject(comment);
}
}
});
模板: 模板是另一个模板内呈现的模态分量。打开它的{{#link-to}}通过传递一组注释。该属性在{{#each}}之外生效,但它内部必须是未定义的,因为即使尝试在第一个单元格中输出它,渲染时也不会显示任何内容。
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Comments</th>
{{#unless hideDeleteButton}}
<th></th>
{{/unless}}
</tr>
</thead>
<tbody>
{{#each}}
<tr>
<td>
{{hideDeleteButton}}
<br>
{{comment}}
</td>
<td>
{{createdByResource}}{{hideDeleteButton}}
</td>
{{#unless hideDeleteButton}}
<td class="text-center">
{{confirm-delete-button action="deleteComment" param=this}}
</td>
{{/unless}}
</tr>
{{/each}}
</tbody>
</table>
似乎用,除非工作。想想,除非像一个不是。你可以尝试并多解释一下你在找什么? – blackmind 2014-11-05 23:20:08
它在bin中工作,我无法弄清楚为什么在这个世界里它不会在我的代码中工作,这非常简单。如果我使用If助手,一切正常。如果我只是将“如果”更改为“除非”,然后切换我的财产的平价,突然它不起作用。我想也许有一些错误,除非在每个帮手或其他内部。 – redOctober13 2014-11-05 23:35:56
看起来不像一个烬虫。我改为v1.6,它仍然运作(它使用1.8)。你可以添加你的程序中的代码,看看是否有区别 – blackmind 2014-11-05 23:40:14