我想用angular和json用ng-repeats内的单选按钮替换标签。我显示具有子产品的产品列表。我希望能够在每个子产品(例如Product1-Type1)旁边放置一个单选按钮,并按父产品代码(例如Product1)进行分组。如果用户选择了一个子产品,则“ Selected”值将为设置为true,其他子产品将设置为false。并且还调用displayFullPricing(prices)函数。
这是用于显示json的代码(有效)
<div ng-repeat="product in groups.Products">
<h3>{{product.Code}}</h3>
<div ng-repeat="prices in product.Prices">
{{prices.Code }} - {{prices.monthly.RetailPrice}}
<a ng-click="displayFullPricing(prices)">select</a>
</div>
</div>
我正在使用的json ...
{
"ID":"",
"Groups":[
{
"Products":[
{
"Code":"Product1",
"Prices":[
{
"Code":"Product1-Type1",
"Monthly":{
"RetailPrice":2,
"MinimumPrice":4
},
"Selected":false
},
{
"Code":"Product1-Type2",
"Monthly":{
"RetailPrice":5,
"MinimumPrice":2
},
"Selected":false
}
]
},
{
"Code":"Product2",
"Prices":[
{
"Code":"Product2-Type1",
"Monthly":{
"RetailPrice":7,
"MinimumPrice":3
},
"Selected":false
},
{
"Code":"Product2-Type2",
"Monthly":{
"RetailPrice":2,
"MinimumPrice":8
},
"Selected":false
}
]
}
]
}
]
}
谁能帮助我实现这一目标?我曾尝试将ng-click移至单选按钮,但没有成功。非常感谢
这是给你的朋克。
关键是为广播组使用相同的名称,因此我使用其父产品来命名。
<input type="radio" name="group-{{product.Code}}" ng-model="subProduct.Selected">{{subProduct.Code}}
对于函数调用,您可以使用ng-click
。
<input type="radio" ng-click="displayFullPricing()" name="group-{{product.Code}}" ng-model="subProduct.Selected">{{subProduct.Code}}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句