我在控制器上有一個屬性,我們將其稱爲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