我有这个json对象:
{
"title":"Training Pants",
"modifiers":[
{
"id":"1172499777372291315",
"type":"variant",
"title":"Gender",
"variants":[
{
"id":"1172499862214672628",
"modifierId":"1172499777372291315",
"title":"Male"
},
{
"id":"1172499953986044150",
"modifierId":"1172499777372291315",
"title":"Female"
},
{
"id":"1172500083497763064",
"modifierId":"1172499777372291315",
"title":"Junior"
}
]
},
{
"id":"1172500938313695482",
"type":"single",
"title":"Cuffs",
"variants":[
{
"id":"1172501102411645179",
"modifierId":"1172500938313695482",
"title":"Elasticated"
},
{
"id":"1172501247098355967",
"modifierId":"1172500938313695482",
"title":"Combination"
},
{
"id":"1172501400207229187",
"modifierId":"1172500938313695482",
"title":"Open End"
}
]
},
{
"id":"1172501710124351751",
"type":"single",
"title":"Pockets",
"variants":[
{
"id":"1172501859257024776",
"modifierId":"1172501710124351751",
"title":"Open Side"
},
{
"id":"1172502043185643794",
"modifierId":"1172501710124351751",
"title":"Zipped Side"
}
]
},
{
"id":"1172502381967966492",
"type":"single",
"title":"Accessories",
"variants":[
{
"id":"1172502597169316125",
"modifierId":"1172502381967966492",
"title":"Waist Cord"
},
{
"id":"1172502756494147870",
"modifierId":"1172502381967966492",
"title":"No.5 Chunky Zip (12\" Leg)"
},
{
"id":"1172502919115702559",
"modifierId":"1172502381967966492",
"title":"No.5 Chunky Zip (18\" Leg)"
}
]
}
]
}
如您所见,它有一个修饰符数组。我需要按类型过滤出修饰符,只选择变体。 我写了这样的ng-repeat:
ng-options="gender.title as gender.title for gender in filters = (item.garment.modifiers | filter: { type: 'variant' })"
但这不是我想要的。我真正想要的是修饰符中的变体。我希望我能做到这一点:
ng-options="gender.title as gender.title for gender in filters.variants = (item.garment.modifiers | filter: { type: 'variant' })"
但这不起作用。 有没有一种简单的方法可以做到这一点,还是我必须创建一个函数?
答案 0 :(得分:0)
我认为这应该有效:
ng-options="gender.title as gender.title for gender in filters = (item.garment.modifiers | filter: { type: 'variant' }).variants"