gpt4 book ai didi

javascript - 类型错误 : Cannot assign to read only property 'checked' checkbox

转载 作者:行者123 更新时间:2023-12-03 07:42:40 26 4
gpt4 key购买 nike

我有以下复选框,我对其进行了过滤,但是当我删除过滤器时,复选框就会丢失。我明白为什么 - 但 Angular 不允许我将检查的值附加到我的 ng-model 因为它是只读

HTML:

<div class="modal-content">
<strong>ENTITIES</strong>
<div>
<div>
<input type="text" placeholder="Search" ng-model="simpleFilter">
<button type="button" ng-click="showModal=false">Ok</button>
</div>
</div>
<br/>
<div ng-repeat="entity in entityArray | filter:simpleFilter">
<label>
<input style="display: inline-block;
margin-top: 5px;"
type="checkbox" ng-model="entity.checked"
ng-change="getEntityFromModal(entity, entity.checked)" />
<a>{{entity}}</a>
</label>
</div>
</div>

我正在尝试将 entity.checked 值传递给函数,我什至不确定如果检查的话它的计算结果是否为真,如果没有则为假,但错误发生在这之前,它根本不允许我将 checked 附加到 entity

笨蛋https://plnkr.co/edit/2ptIAdOyaIw8mGqpU7Cp?p=preview - 打开控制台并尝试选中一个框。

最佳答案

您需要在模型中创建与 View 绑定(bind)的属性。

编辑 $scope.entityArray 如下:

$scope.entityArray = [{'val':11,'checked':false},{'val':22,'checked':false},{'val':33,'checked':false}];

关于javascript - 类型错误 : Cannot assign to read only property 'checked' checkbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35345387/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com