以下面的示例为例,如果未选中复选框,则禁用按钮并在选中时启用它:
车把:
<form {{action "register" on="submit"}}>
{{input type="checkbox" checked=isAgreed}}
{{input type="submit" value="Register" class="btn btn-primary" disabled=isNotAgreed}}
</form>
Javascript:
App.ApplicationController = Ember.ObjectController.extend({
content:{
isAgreed:false
},
isNotAgreed:function(){
return !this.get('isAgreed');
}.property('isAgreed'),
actions:{
register:function(){
alert("registered");
}
}
});
如本JSBin所示。
我想知道是否有更清洁的方法来做到这一点。例如,删除isNotAgreed
observable 属性并在我的车把模板中使用一些东西,比如{{input type="submit" value="Register" disabled=!isAgreed}}
. 有没有办法做到这一点?