我正在尝试将 a 的类设置<tr>
为#warning
或者#success
取决于我的服务器模型的 percentFree 属性。这是我的车把模板:
<script type="text/x-handlebars" data-template-name="dashboard">
<h1>Virtual Image Overview</h1>
<table class="table table-hover">
<thead>
<tr>
<th>Machine Name</th>
<th>Drive</th>
<th>Total Size</th>
<th>Used Space</th>
<th>% free</th>
</tr>
</thead>
<tbody>
{{#each controller}}
<tr {{bindAttr class="status"}}>
<td>{{name}}</td>
<td>{{drive}}</td>
<td>{{totalSize}}</td>
<td>{{usedSpace}}</td>
<td>{{percentFree}}</td>
</tr>
{{/each}}
</tbody>
</table>
</script>
这是我的模型:
Dashboard.Server = DS.Model.extend({
name: DS.attr('string'),
drive: DS.attr('string'),
totalSize: DS.attr('number'),
usedSpace: DS.attr('number'),
percentFree: DS.attr('number'),
status: "",
setStatus: function() {
if(this.percentFree <= 0.50) {
this.status = "warning";
} else {
this.status = "success";
}
}
});
尽管 的类<tr>
从未真正更新过。有没有更有效(正确)的方法来解决这个问题?
我也尝试status: this.setStatus()
过
setStatus: function() {
if(this.percentFree <= 0.50) {
return "warning";
} else {
return "success";
}
}
没有运气