我有一些json数据: 请注意,大小是一个大字符串而不是数组
$scope.productData = {
colors_and_sizes: {
data: {
Black:
{
sizes: "X Small, Small, Medium, Large, Xlarge, XX Large"
}
Blue:
{
sizes: "X Small, Small, Medium, Large, Xlarge, XX Large"
}
}
}
}
和一些html:
<form>
<div class="color-pick" ng-repeat="(key, val) in productData.colors_and_sizes.data">
<input type="radio" ng-model="myColor" ng-value="{{key}}"/>
<div class="size-pick">
<!-- it's weird cuz the sizes are a big string? how to set ng-options" -->
<select ng-model="mySize" ng-options=""></select>
</div>
</div>
</form>
答案 0 :(得分:3)
实际上我猜你要问的是,你有一个字符串用于密钥大小,你希望用{1}}用单选按钮填充
如果那就是看看这个。
<强> Working Demo 强>
<强> HTML 强>
ng-options
另外我要说的是你所展示的json不正确,它应该如下所示
<div class="color-pick" ng-repeat="(key, val) in productData.colors_and_sizes.data">
<input type="radio" name="colors" ng-model="myColor" ng-value="{{key}}" />{{key}}
<div class="size-pick">
<select ng-model="mySize" ng-options="size for size in val.sizes.split(',')"></select>
</div>
</div>