ng show显示所有项目
ng-show Displaying all items
继续使用angularjs,现在ng-show出现问题,点击后会显示所有隐藏的数据。正如我所理解的,我需要指定我想要显示的点击项目的ID,从我的例子中,我使用的是具有布尔值的ng模型,点击后它变为true,这就是为什么它显示所有项目的原因。请告诉我,我如何显示我选择的项目?
<div class="list-group" ng-click="SetItemVisible()" ng-repeat="q in feed">
<a href="" class="list-group-item">
<h4 ng-model="showItem" class="list-group-item-heading">{{q.title}}</h4>
<p ng-show="showItem" value="true" class="list-group-item-text">{{q.body}}</p>
</a>
</div>
js:
$scope.SetItemVisible = function () {
if (!$scope.showItem) {
$scope.showItem = true;
} else {
$scope.showItem = false;
}
}
$scope.feed = [];
function getRssItems() {
rssFeedService.getFeed().then(function (results) {
$scope.feed = results.data;
}, function (error) {
//alert(error.data.message);
});
}
您可以通过以下方式进行dis:
$scope.feed = [{
'title': "A",
'body': "testA body"
},
{
'title': "b",
'body': "testb body"
}
]
$scope.showItem = {};
$scope.SetItemVisible = function (index) {
$scope.showItem[ index] = true;
}
<div class="list-group" ng-click="SetItemVisible($index)" ng-repeat="q in feed track by $index">
<a href="" class="list-group-item">
<h4 ng-model="showItem[$index]" class="list-group-item-heading">{{q.title}}</h4>
<p ng-show="showItem[$index]" value="true" class="list-group-item-text">{{q.body}}</p>
</a>
如需现场演示,请单击此处:http://plnkr.co/edit/ApI9eb8eQlBdoMUkn8do?p=preview
<div class="list-group" ng-click="q.showItem != q.showItem" ng-repeat="q in feed">
<a href="" class="list-group-item">
<h4 ng-model="showItem" class="list-group-item-heading">{{q.title}}</h4>
<p ng-show="q.showItem" value="true" class="list-group-item-text">{{q.body}}</p>
</a>
</div>
假设以下JSON用于馈送
[
{
"title":"test1",
"body":"test body 1",
"show":false
},
{
"title":"test2",
"body":"test body 2",
"show":false
}
]
HTML
<body ng-controller="MainCtrl">
<div class="list-group" ng-repeat="q in feed">
<a class="list-group-item">
<h4 ng-click="q.show=!q.show" class="list-group-item-heading">{{q.title}}</h4>
<p ng-show="q.show" value="true" class="list-group-item-text">{{q.body}}</p>
</a>
</div>
JS-
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $http) {
$scope.feed = [];
$http.get('feed.json').then(function (results) {
$scope.feed = results.data;
}, function (error) {
//alert(error.data.message);
});
});
点击此处查看
相关文章:
- 角度的项目列表 ng 重复,ng 单击显示全宽描述
- 我怎样才能重复显示接下来的15个项目
- 隐藏/显示包含单词的ul li项目.但只能入住李的子女
- Javascript中的列表,用于添加和显示所有项目
- 如何在点击时显示ul项目
- 限制ul元素中显示的项目
- 在underscore.js中显示列表中的所有项目(使用Parse.com)
- PHP无法显示带有“”的项目'"在他们身上
- HTML选择,在DOM中选择了正确的选项,但在firefox中显示了错误的项目
- 获取中继器控件ASP.Net中显示的单击项目文本框
- 仅显示具有userid作为子项的项目
- 从项目列表Jquery中仅选择(显示:块)元素
- 首先显示选择最多的项目
- 如果项目不匹配,则显示变量
- 只有一个项目显示在 x 轴 d3 中 - 使用刻度值的序号
- 在 HTML 中将数组的每个项目显示为换行符
- 如何正确使用熨斗可选?像铁页一样使用时,项目显示为null
- Html, javascript:滚动列表框项目-并为每个项目显示提示
- 根据从下拉列表中选择的项目显示ViewBag的属性并发布ID
- 如何向选中的项目显示一个箭头?