我正在使用角度过滤器“groupBy”(https://github.com/a8m/angular-filter#groupby)来显示主题中的课程,如下所示:
<div ng-repeat="(key, value) in lessonList | filter:search | groupBy: 'lesson.subject.name'">
<div>
<strong> {{key}}</strong>
</div>
<div >
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="t in value">
<td>{{t.lesson.id}}</td>
<td>{{t.lesson.name}}</td>
<td>
<input type="radio" ng-model="t.status" ng-value="1"> Complete
<input type="radio" ng-model="t.status" ng-value="2"> Incomplete
Selected Status: {{t.status}}
</td>
</tr>
</tbody>
</table>
</div>
</div>
当我第一次选择上述状态单选按钮时,状态值会发生变化(从1到2,反之亦然)。然后我将此信息保存到数据库中。现在,如果我离开此页面并通过单击“查看和编辑”按钮再次返回此页面并单击单选按钮,“选定状态:{{t.status}}”行内的状态将更改,而< strong> lessonList 对象不会更改。我编写了另一段代码来查看 lessonList 中的更改,如下所示, test.status 不会随着单选按钮的更改而改变:
<div>
<ul ng-repeat="test in lessonList ">
<li> {{test.lesson.id}}</li>
<li> {{test.status}}</li>
</ul>
</div>
但是,如果我刷新浏览器,然后单击“编辑”页面中的单选按钮,则 lessonList 会更新。是因为{{value}}仅更新,而不是 lessonList 当单选按钮更改时,如何更新 lessonList ?每次更改单选按钮的值时,我都需要更改lessonList对象的状态。我的数据如下所示:
$scope.lessonList = [
{lesson: {id: 1, name: 'Lesson 1', subject: {name: 'Maths', standard: 1}, status: 1},
{lesson: {id: 2, name: 'Lesson 2', subject: {name: 'Maths', standard: 1}}, status: 2},
{lesson: {id: 3, name: 'Lesson 1', subject: {name: 'Science', standard: 2}}, status: 1},
{lesson: {id: 4, name: 'Lesson 3', subject: {name: 'Science', standard: 2}}, status: 2}
];
过滤器:搜索正在过滤标准,即search.subject.standard 任何帮助/建议表示赞赏,谢谢!