在编辑记录时,数据会进入各自的编辑字段,但如果其值为 1
,则不会选中该复选框。
如果它有1
,它应该处于检查状态,如果它有0
,则不检查,因为该字段的数据类型是tinyint
。我正在通过 PHP 从 JSON 数组中检索数据。我试图通过 ng-checked="{{rec.isSpecial}}"
获取值,但它不起作用。
这是我的 HTML:
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox c-checkbox">
<label>
<input type="checkbox" ng-checked="{{rec.isSpecial}}" ng-model="rec.isSpecial">
<span class="fa fa-check"></span>Special
</label>
</div>
</div>
</div>
这是我的JS
$scope.rec = $resource('api/AdminArea/category/edit/:id', {
id: id
}).get(function(data) {
$scope.rec = data;
});
最佳答案
由于您的数据返回数字而不是真值或假值,您可以这样做:
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox c-checkbox">
<label>
<input type="checkbox" ng-checked="rec.isSpecial==1" ng-model="rec.isSpecial">
<span class="fa fa-check"></span>Special
</label>
</div>
</div>
</div>
参见 fiddle了解更多信息
关于javascript - 如何使用 AngularJS 在数据库的复选框中设置默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34333733/