【发布时间】:2016-05-07 19:12:51
【问题描述】:
我有一个显示项目列表的角度页面。它遍历列表并将其显示在 div 中。这是它的 HTML 代码:
<div ng-repeat="item in items">
<div class="item-title-section">
<h1>{{item.text}}</h1>
</div>
<div class="item-special-section"
ng-show="item.type == 'FooB' ||
item.type == 'FooC' ||
item.type == 'FooD'">
<div>
<h2>Speical</h2>
<p>Type Section</p>
</div>
<div>
<span>{{item.text}}</span>
</div>
</div>
</div>
item-title-section 始终显示。但我只希望item-special-section 显示当前项目的类型是 B、C 还是 D。这里的问题是如果列表包含所有 3 个项目,我只希望 div 打印一次,但每个项目的文本打印。所以在这种情况下:
{
{
type: FooA,
title: FooA,
text: "Some text for this element"
},
{
type: FooB,
title: FooB,
text: "Some text for this element"
},
{
type: FooC,
title: FooC,
text: "Some text for this element"
}
}
item-special-section div 打印两次。有没有一种角度静态创建html元素的方法,这意味着 if 它只创建一次?
【问题讨论】:
-
什么是当前项目?
标签: javascript jquery css angularjs static