gpt4 book ai didi

javascript - ng-repeat 元素删除属性

转载 作者:行者123 更新时间:2023-12-02 13:45:08 25 4
gpt4 key购买 nike

所以我有以下ng-repeat:

<th ng-repeat="field in tableFields" translate="{{field.headerTitle | translate}}"
ts-criteria="{{field.sortable ? field.fieldKey : null}}">
<label class="i-checks" ng-if="field.isCheckbox">
<input type="checkbox" ng-model="checkAll" ng-change="selectAll(checkAll)">
<i></i>
</label>
</th>

这工作正常,但由于外部脚本中存在一些错误,如果 field.fieldKey 为 null,则不应设置 ts-criteria。所以我的问题是如何完全删除该属性?

最佳答案

如果认为一个好的选择是使用 ng-switch 来选择是否应设置您的属性。

没有完整的代码,但它会是这样的:

<div ng-switch on="myVar">
<th ng-switch-when="true" ts-criteria>ts-criteria here</th>
<th ng-switch-default>not here</th>
</div>

Here is a demo on JSFiddle

通过更改 myVar 值来尝试

关于javascript - ng-repeat 元素删除属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41464450/

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