【发布时间】:2014-10-10 13:37:27
【问题描述】:
我正在学习 Angular,并且正在尝试构建一些零碎的东西来学习。我试图在下面尽可能清楚地解释自己 - 任何帮助将不胜感激。
示例: http://jsbin.com/micasafetise/2/ http://jsbin.com/micasafetise/2/edit?html,js,console,output
我自己创建了这些数据
$scope.people =
[
{
"personID": 1,
"first_name": "Sam",
"last_name": "Stimpson",
"attending": false
},
{
"personID": 2,
"first_name": "Alison",
"last_name": "van Schoor",
"attending": true
},
{
"personID": 3,
"first_name": "Lindsay",
"last_name": "van Schoor",
"attending": false
}
];
我在我的视图中创建了这样的输出:
<div ng-repeat="person in people">
<a href="" ng-click="isAttending()">
{{person.first_name}}{{person.last_name}} - {{person.attending}}
</a>
</div>
现在我被困住了。我希望能够单击一个人并将其参加字段从 false 更新为 true。我知道我可以像这样使用 ng-click
$scope.isAttending = function() {
alert("is attending");
};
但不知道如何更新我点击的人以在 $scope.people 中将 false 更改为 true。
当我实现这一点时,我计划再进行一次带有过滤器的 ng-repeat,以向参加者展示,但我相信我能够做到这一点。
任何人都可以帮助我或给我一些建议,目前任何事情都会非常感激。
提前致谢。
我写了一个我在这里尝试做的例子: http://jsbin.com/micasafetise/2/ http://jsbin.com/micasafetise/2/edit?html,js,console,output
【问题讨论】:
-
不是 json 而是 javascript 对象。
标签: angularjs angularjs-scope angularjs-ng-repeat angularjs-filter