从角度JS和离子选择中选择选项

时间:2015-09-09 20:21:37

标签: javascript php json angularjs ionic-framework

我对角度J的select有一些问题,我搜索了很多但找到了一些解决方案但没有工作。

我有一个像我的 service.php

生成的Json Structured
[
    {
        "Name": "Name1",
        "Variante": [
            {
                "Prix": "79.00",
                "Name": "20 Piéces"
            }
        ],
        "Description": "",
        "main_image": "images/products/DSC_0192.jpg"
    },
    {
        "Name": "NAME2",
        "Variante": [
            {
                "Prix": "39.00",
                "Name": "250g"
            },
            {
                "Prix": "60.00",
                "Name": "500g"
            }
        ],
    "Description": "",
    "main_image": "images/products/DSC_0125.jpg"
    }
]

这是我的 controller.js

.controller('productsCtrl', function($scope, $http, $stateParams) {
    $http.get('service.php')
    .success(function (response) {
        $scope.products = response;
    });
});

这是我的 products.html

<ion-view view-title="Products">
    <ion-content>
        <ion-list>
            <ion-item style="background-image: url({{product.main_image}})" 
            ng-repeat="product in products" class="productListItem">
                <h2 class="h2Name">{{product.Name}}</h2>

                <button class="button button-balanced button-right">
                    <i class="icon ion-ios-cart"></i>
                </button>

                <select class="Variantes" 
                    ng-if="product.Variante.length > 1" 
                    ng-model="selectedItem"
                    ng-options="variant.Name for variant in product.Variante">
                </select>

                <h2 class="Variantes" ng-if="product.Variante.length == 1">
                    {{product.Variante[0].Name}}
                </h2>
                <h2 class="h2Price" ng-if="product.Variante.length > 1">
                    {{selectedItem.Prix}}
                </h2>
                <h2 class="h2Price" ng-if="product.Variante.length == 1">
                    {{product.Variante[0].Prix}}
                </h2>

            </ion-item>
        </ion-list>
    </ion-content>
</ion-view>

如果我有多个Variante,我希望在更改选择框时能够更改价格(Prix)值。但它没有用。

需要任何帮助!!

由于

0 个答案:

没有答案