从select中获取其他值

时间:2015-05-31 05:20:59

标签: angularjs

我有一个包含服务值的数组:

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>

1 个答案:

答案 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>