gpt4 book ai didi

javascript - 访问 Controller 中的 ng-repeat 变量

转载 作者:行者123 更新时间:2023-11-28 13:24:16 24 4
gpt4 key购买 nike

这是我目前拥有的:

HTML

            <center><li ng-repeat = "x in items | orderBy: 'priority'"> 
<!-- color code priorities -->
<span ng-style="cmplt" ng-class="{ red: x.type == 'Work', blue: x.type == 'Personal' }">
<b>{{ x.name }}</b></span>
<span ng-class="{ yourChore: x.assignedTo == username} ">
- {{ x.type }} (Priority {{ x.priority }}) Assigned by {{ x.creator }} to {{ x.assignedTo }}
</span>&nbsp;&nbsp;

<!-- When task is completed, user can click this button to mark it as such -->
<button type="button" ng-click="cmplt={color: 'gray', 'text-decoration': 'line-through'} ;
markAs(this)">Completed</button>
<div ng-class="{ red: x.completed == true }"> Hello</div>
<button type="button" ng-click = "comment = true">Comment</button>
<div ng-show="comment"><textarea rows="3" columns="50" ng-model="x.comments"></textarea></div>
<div>{{ x.comments }}</div>
</li></center>

JavaScript

    $scope.markAs = function(repeatScope){
if (!repeatScope.completed){
repeatScope.completed = true;
}
else {
repeatScope.completed = false;
}
};

正在重复的对象中有一个 bool 值,默认情况下标记为 false,但单击按钮时应重新评估为 true。问题是这不会发生(保持错误),我不确定为什么基于我的代码。

最佳答案

您可以通过 ng-repeat 中定义的内容传入当前元素:

<li ng-repeat="x in items"> <!-- reference to x within the repeat scope -->
<button type="button"
ng-click="cmplt={color: 'gray', 'text-decoration': 'line-through'}; markAs(x)">
Completed
</button>
</li>

关于javascript - 访问 Controller 中的 ng-repeat 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30461938/

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