所以我向 HomeView 添加了一个方法,如下所示:
App.HomeView = Ember.View.extend({
isFailed: function () {
console.log(this);
return "FAILED" === this.get("state");
}
});
在 HTML 中,这是主页模板的外观。如您所见,我在循环中调用 isFailed 函数,由于某种原因,它从未被调用(日志中没有任何内容):
<script type="text/x-handlebars" id="home">
<table>
<thead>
<tr>
<th>ID</th>
<th>Status</th>
<th>Foo</th>
<th>Bar</th>
</tr>
</thead>
<tbody>
{{#each}}
<tr>
<td>{{id}}</td>
<td>
{{#if isFailed }}
FAILED
{{/if}}
</td>
<td>bar</td>
<td>foobar</td>
</tr>
{{/each}}
</tbody>
</table>
</script>
知道为什么没有调用 isFailed 函数吗?
jsfiddle:http: //jsfiddle.net/dWxTn/2/