我在控制器上有一个属性,我们将其称为showTheStuff
,并且我的模板中包含一个{{#each}}
帮助器。现在,我只是显式设置该属性。
在该列表中,我想根据的值有条件地渲染或不渲染某些标记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>
@ Kingpin2k引导我朝着正确的方向发展,我猜这个jsbin与我的实际代码不完全匹配。问题是我的hideDeleteButton属性实际上在每个对象中都不知道,因为它遍历传入的模型。
但是,如果我controller
在引用该属性时指定了,它将起作用!
{{#unless controller.hideDeleteButton}}
<td class="text-center col-md-1">
{confirm-delete-button action="deleteComment" param=this}}
</td>
{{/unless}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句