我想使用AngularJS以切换方式显示和隐藏与特定ID相关的数据。
我的JSON数据格式如下:
$scope.things = [{
id: 1,
data: 'One',
shown: true
}, {
id: 2,
data: 'Two',
shown: false
}, {
id: 3,
data: 'Three',
shown: true
}, ];
我想要的是单击id-1时将显示文本1和隐藏其他,单击id-2时将显示文本2和隐藏其他,依此类推。
这是我尝试的小提琴:jsfiddle:演示链接
我更新了您的代码
$scope.flipMode = function (id) {
$scope.things.forEach(function (thing) {
if(id == thing.id){
thing.shown = true;
}
else{
thing.shown = false;
}
})
};
<a href="#" ng-click="flipMode(thing.id)">{{thing.id}}</a>
这是工作的小提琴
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句