选择带角度的嵌套json
我有一个用json填充的选择框。这里是json选择带角度的嵌套json,json,angularjs,Json,Angularjs,我有一个用json填充的选择框。这里是json { "Connectivity": [ { "product_id": 1, "product_name": "SmartLink", "product_price_attributes": [ { "key": "postcodeA", "type": "text" },
{
"Connectivity": [
{
"product_id": 1,
"product_name": "SmartLink",
"product_price_attributes": [
{
"key": "postcodeA",
"type": "text"
},
{
"key": "BearerBW",
"type": "text"
},
{
"key": "Total bandwidth",
"type": "text"
}
]
},
{
"product_id": 2,
"product_name": "SmartNet",
"product_price_attributes": [
{
"key": "postcodeA",
"type": "text"
},
{
"key": "BearerBW",
"type": "text"
}
]
},
{
"product_id": 3,
"product_name": "Centralised Internet",
"product_price_attributes": [
{
"key": "BearerBW",
"type": "text"
}
]
}
],
"Cloud Services": [
{
...
}
]
}
我在控制器中使用此代码填充下拉列表
$http.get('scripts/json/sample-products.json')
.then(function(res){
$scope.portfolio1 = res.data.Connectivity;
});
这将创建如下所示的选择框
<select ng-model="selectedProduct" ng-options="opt as opt.product_name for opt in portfolio1"
ng-change="getPriceAttributes()">
<option value="0" selected="selected" label="SmartLink">SmartLink</option>
<option value="1" label="SmartNet">SmartNet</option>
<option value="2" label="Centralised Internet">Centralised Internet</option>
因此,我的问题是,我不知道如何深入到所选产品的嵌套对象“product\u price\u attributes”。我不确定需要将什么传递给getPriceAttributes,或者需要对函数进行哪些更改才能使其正常工作
有什么想法吗
非常感谢
selectedProduct
设置为opt
——这是连接
阵列中的每个项目,因此:
console.log($scope.selectedProduct.product_price_attributes)
您还可以将模型作为参数传递给change
函数:
$scope.getPriceAttributes = function(item) {
console.log(item.product_price_attributes)
...
}
<select ng-model="selectedProduct" ng-options="opt as opt.product_name for opt in portfolio1" ng-change="getPriceAttributes(selectedProduct)">
$scope.getPriceAttributes=函数(项){
console.log(item.product\u price\u属性)
...
}
$scope.getPriceAttributes = function(item) {
console.log(item.product_price_attributes)
...
}
<select ng-model="selectedProduct" ng-options="opt as opt.product_name for opt in portfolio1" ng-change="getPriceAttributes(selectedProduct)">