我想做的是创建一个概览,可以根据嵌套在 JSON 对象数组中的类别进行过滤。
我想要创建概览的项目的 JSON 看起来像这样:
{
id: 1,
title: "title",
content: "content",
categories: [{
title: "cat1",
descripton: "desc"
},
{
title: "cat2",
descripton: "desc"
}]
},
{
id: 2,
title: "title",
content: "content",
categories: [{
title: "cat3",
descripton: "desc"
},
{
title: "cat4",
descripton: "desc"
}]
}
HTML 看起来像这样:
<select ng-model="catselect">
<option>cat1</option>
<option>cat2</option>
<option>cat3</option>
<option>cat4</option>
</select>
<ul>
<li ng-repeat="item in array | filter: {ARRAY OF CATEGORIES: catselect}">
</li>
</ul>
目前我不知道如何让它工作。 (我认为)最明显的解决方案应该是类似于 filter: {categories.title: catselect}
但显然不是。据我所知,Stackoverflow 上没有其他问题可以解决这个问题。我很想知道是否有人可以帮助我。
最佳答案
你能试试看它是否有效吗?我实际上并没有测试它。
filter: { categories: { title: catselect } }
关于html - Angular JS 过滤器基于类别数组的概述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38616659/