我有带复选框的模板
<div class="col-sm-6">
<input type="checkbox" id="isDeletedCheckbox" {{action "toggleIsDeleted" "isDeletedCheckbox" on="change"}}/>
</div>
我有路线
afterModel(model) {
this.controllerFor(this.get('routeName')).set('model', model)
},
我尝试使用
setupController() {
if (this.controller.get('model').get('isDeleted')) {
this.controller.set("isDeletedCheckbox", true);
}
}
或者
setupController() {
if (this.controller.get('model').get('isDeleted')) {
$("#isDeletedCheckbox").checked(true);
}
}
但它无助于预设值
您应该使用{{input type="checkbox"}}
助手。
{{input type="checkbox" name="isEmberized" checked=model.isDeleted}}
如果您的模型如下所示:
model() {
return { isDeleted: true };
}
你永远都不会不喜欢的东西
$("#isDeletedCheckbox").checked(true);
在路由或控制器中。仅在组件中使用直接DOM操作!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句