【问题标题】:Angular angucomplete-alt cannot populate the priceAngular angucomplete-alt 无法填充价格
【发布时间】:2015-09-13 15:09:39
【问题描述】:

var app = angular.module('app', ["angucomplete-alt"]);

app.controller('MainController',  function($scope) {

    $scope.countries = [
        {name: 'Hosting 1', code: '100.00'},
        {name: 'Hosting 2', code: '200.00'},
        {name: 'Hosting 3', code: '300.00'},
        {name: 'Hosting 4', code: '400.00'},
        {name: 'Hosting 5', code: '500.00'},
        {name: 'Hosting 6', code: '600.00'},

    ];

    $scope.countrySelected = function(selected) {
        //$scope.invoice.item.lol = 1;
        window.alert('You have selected ' + selected.title);

    };

    $scope.taxesData = {
        singleSelect: null,
        availableOptions: [
            {id: '6.50', name: '6,5%'},
            {id: '16.00', name: '16%'},
            {id: '23.00', name: '23%'}
        ],
        selectedOption: {id: '23.00', name: '23%'}
    };

    $scope.invoice = {
        items: [{
            description: '',



        }]
    };

    $scope.addItem = function() {
        $scope.invoice.items.push({
            description: '',
            price: 10.99,

        });
    };

        $scope.removeItem = function(index) {
            $scope.invoice.items.splice(index, 1);
        };

        $scope.total = function() {
            var total = 0;
            angular.forEach($scope.invoice.items, function(item) {
                total += item.qty * item.price;
            })
            return total;
        };

        $scope.taxtotal = function() {
            var taxtotal = 0;
            angular.forEach($scope.invoice.items, function(item) {
                taxtotal += item.qty * item.price * item.taxesData.repeatSelect * 0.01;
            })
            return taxtotal;
        };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!--ng-controller="MainController"-->
<div ng-app="app"><div ng-controller="MainController">

        <table class="table table-condensed table-striped">
            <tr>

                <th>Product Name</th>
                <th>Item Price</th>
                <th>Qty</th>
                <th>Tax Rate</th>
                <th>Line Total</th>
                <th>Line Taxes Total</th>
                <th></th>
            </tr>
            <tr ng:repeat="item in invoice.items">
                <td angucomplete-alt id="ex1" placeholder="Search countries" maxlength="50" pause="100" selected-object="selectedCountry" local-data="countries" search-fields="name" title-field="name" minlength="1" input-class="form-control form-control-small" match-class="highlight"></td>
                <td><input type="text" value="{{selectedCountry.originalObject.code}}"></td>

                <td><input type="text" ng:model="item.qty" ng:required class="input-mini"></td>
                <!--<td><input type="text" ng:model="item.taxRate"class="input-small"></td>-->
                <td>
                    <select name="repeatSelect" ng-model="item.taxesData.repeatSelect">
                        <option ng-repeat="option in taxesData.availableOptions" value="{{option.id}}">{{option.name}}</option>
                    </select>
                </td>
                <td>{{item.qty * item.mama  | currency}}</td>
                <td>{{item.qty * itme.mama * item.taxesData.repeatSelect * 0.01 | currency}}</td>


                <td>
                    [<a href ng:click="removeItem($index)">X</a>]
                </td>
            </tr>
            <tr>
                <td><a href ng:click="addItem()" class="btn btn-small">add item</a></td>
                <td></td>
                <td>Totals:</td>
                <td></td>
                <td>{{total() | currency}}</td>
                <td>{{taxtotal() | currency}}</td>
            </tr>
        </table>


    </div>
</div></div>

正如您在 jfiddle 中看到的那样,我正在使用 angular 和 angucomplete-alt 插件来管理订单。

我有一个范围“国家”,它提供自动完成框。

现在我正在尝试, 在选择一个国家(产品:P)时,我希望为项目价格字段提供正确的值(例如,如果我选择托管 1,则项目价格必须以 100.00 的值完成。

问题是:

1) 如果我将 ng:model 设置为该字段(因为我想使用总计的价格)该字段未完成。

2) 如果我只设置 value="{{selectedCountry.originalObject.code}},则该字段已完成,但我没有 ng:object 用于总计。

【问题讨论】:

    标签: angularjs autocomplete


    【解决方案1】:

    如果您将ng:model 设置为以下内容,它应该可以为您的价格 输入字段:

    <input type="text" ng:model="selectedCountry.originalObject.code">
    

    working fiddle

    【讨论】:

    • 如此简单!你是最好的迈克尔!谢谢!但是现在我有一个新问题!基本上我无法计算总数(不是行总数)。 jsfiddle.net/limeframe/Leho4218/9 谢谢
    猜你喜欢
    • 1970-01-01
    • 2016-09-13
    • 2015-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多