我有一个包含服务值的数组:
serv.success(function (data) {
$.each(data.records, function(i, product) {
saleItem.push({
value: product.id,
text: product.name,
price: product.price
});
});
});
我想在选择特定选项时获取price
值:
<select ng-model="product.id" ng-options="s.value as s.text for s in saleItem">
<option style="display:none" value="">Selecione um Produto</option>
</select>
答案 0 :(得分:0)
尝试使用此
<body ng-app="myApp" data-ng-controller="HomeCtrl">
<select ng-model="product.id" ng-options="s.price as s.text for s in saleItem">
<option style="display:none" value="">Selecione um Produto</option>
</select>
<p>price is {{product.id}}</p>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script>
angular.module('myApp', []);
angular.module('myApp').controller('HomeCtrl', ['$scope', function($scope) {
$scope.saleItem = [
{
"value":1,
"text":"p1",
"price":100
},
{
"value":2,
"text":"p2",
"price":200
}
]
}]);
</script>
</body>