我有类别和子类别链接到范围varibales中的类别。尝试使用此数据创建表。
<table>
<tr ng-model = "SelectedCategory" ng-repeat="x in Categories | filter:{mapid: SelectedSuperCategory.id}:true">
<td>{{ x.name }}</td>
<br>
<td>{{ x.id }}</td>
<td>
<table>
<tr ng-repeat="y in SubCategories | filter:{mapid: {{ x.id }} }:true">
<td>{{ y.name }}</td>
</tr>
</table>
</td>
</tr>
</table>
我在子类别过滤器中传递categoryid时遇到了麻烦。
有人可以帮我解决这个问题吗?
类别数据
[
{
"name": "Baby Food",
"id": "200",
"image": "/images/categories/baby-care.png",
"mapid": "2"
},
{
"name": "Baby Bath",
"id": "201",
"image": "/images/categories/baby-care.png",
"mapid": "2"
},
{
"name": "Baby diapers",
"id": "202",
"image": "/images/categories/baby-care.png",
"mapid": "2"
},
{
"name": "Dairy Products",
"id": "503",
"image": "/images/categories/baby-care.png",
"mapid": "5"
},
{
"name": "Others2",
"id": "101",
"image": "/images/categories/others.png",
"mapid": "3"
},
{
"name": " Bread",
"id": "501",
"image": "/images/categories/dairy-products.png",
"mapid": "5"
},
{
"name": "Beverages",
"id": "103",
"image": "/images/categories/beverages.png",
"mapid": "23"
},
{
"name": "Bakery",
"id": "502",
"image": "/images/categories/others.png",
"mapid": "5"
},
{
"name": "Others2",
"id": "105",
"image": "/images/categories/others.png",
"mapid": "23"
}
]
子类别数据
[
{
"name": "Milk",
"id": "5000",
"image": "/images/categories/baby-care.png",
"mapid": "503"
},
{
"name": "Cheese",
"id": "5001",
"image": "/images/categories/baby-care.png",
"mapid": "503"
},
{
"name": "Paneer",
"id": "5002",
"image": "/images/categories/baby-care.png",
"mapid": "503"
},
{
"name": "Baby Care",
"id": "100",
"image": "/images/categories/baby-care.png",
"mapid": "5"
},
{
"name": "Others2",
"id": "101",
"image": "/images/categories/others.png",
"mapid": "3"
},
{
"name": " Bread, Bakery & Dairy Products",
"id": "102",
"image": "/images/categories/dairy-products.png",
"mapid": "5"
},
{
"name": "Beverages",
"id": "103",
"image": "/images/categories/beverages.png",
"mapid": "23"
},
{
"name": "Others",
"id": "104",
"image": "/images/categories/others.png",
"mapid": "5"
},
{
"name": "Others2",
"id": "105",
"image": "/images/categories/others.png",
"mapid": "23"
}
]
答案 0 :(得分:2)
您不需要在过滤器中插入类别ID,ng-repeat使其可用作范围变量。
所以而不是
<tr ng-repeat="y in SubCategories | filter:{mapid: {{ x.id }} }:true">
使用
<tr ng-repeat="y in SubCategories | filter:{mapid: x.id}:true">