【发布时间】:2018-07-14 13:01:40
【问题描述】:
我想在我的页面上显示文章列表。首先显示所有内容,但是如果用户单击一个按钮,它只会显示与单击的按钮相关的文章。这意味着它将查看数组中的“葡萄”,如果它是红色的,则显示列表中的红酒。最好有一个按钮来显示默认返回初始视图的所有内容。欢迎任何帮助。
<button>Show ALL Articles<button>
<button ng-click="filter('red')">Show me articles with red wines<button>
<button ng-click="filter('white')">Show me articles with white wines<button>
<button ng-click="filter('rose')">Show me articles with rose wines<button>
<ul>
<li ng-repeat="item in wineListings | filter: filter">
<h2>{{item.country}}</h2>
<p>{{item.grape}}</p>
</li>
</ul>
$scope.wineListings = [
{
country:"France",
grape:"red"
},
{
country:"Spain",
grape:"red"
},
{
country:"Italy",
grape:"white"
},
{
country:"USA",
grape:"rose"
}
];
【问题讨论】:
-
到目前为止你有什么尝试?
-
嗨,安德鲁,我尝试了上述方法(刚刚编辑了我的原始代码以包含我的尝试)
标签: javascript arrays angularjs