淘汰赛js网格ajax呼叫无法正常工作 [英] Knockout js grid ajax call not working

查看:80
本文介绍了淘汰赛js网格ajax呼叫无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网格有价格,数量列。我需要计算总数ie。价格*数量。它的工作新行只。但我从Web服务获取数据并将其加载到网格中。现在我正在查询数值,但计算不起作用。它的工作添加了一个新行。请帮忙..



我尝试过:



<脚本> 

var quotationViewModel = function(quotations){
var self = this;

self.quotations = ko.observableArray(ko.utils.arrayMap(quotations,function(item){
return new Item(item);
}));

self.addquotation = function(){
self.quotations.push(new Item());

UIValidation();
};

self.removequotation = function(quotation){
self.quotations.remove(quotation);
};
self.savequotation = function(){
return ko.utils.stringifyJson(self.quotations);
}
self.grand_total = ko.computed(function(){
var total = 0;
for(var p = 0; p< self.quotations()。长度; ++ p){
total + = self.quotations()[p] .total();
}
return total.toFixed(2);
}) ;

self.Tax_Total = ko.computed(function(){
var tax = 0;
for(var p = 0; p< self.quotations()。length ; ++ p){
tax + = self.quotations()[p] .tax_calc();
}
return tax.toFixed(2);
});

self.grandTax = ko.computed(function(){
var tax = 0,sum = 0,totalsum = 0;
for(var p = 0; p< ; self.quotations()。length; ++ p){
tax + = self.quotations()[p] .tax_calc();
sum + = self.quotations()[p]。 total();
totalsum = tax + sum;
}
$('#grandTax')。val(totalsum.toFixed(2));
$('#totalAmt ').val(totalsum.toFixed(2));
$('#TotalVat_Amt')。val(tax.toFixed(2));
return totalsum.toFixed(2);
});

function item(item){
var self = this;
self.P055_ID = ko.observable('');
self.itemCode = ko.observable('');
self.itemDesc = ko.observable('');
self.packing = ko.observable();
self.VatCode = ko.observable();
self.VatDesc = ko.observable();
self.taxID = ko.observable();
self.tax_perc = ko.observable(0);
self.quantity = ko.observable(0);
self.rate = ko.observable(0);
self.remarks = ko.observable();

for(var k in item)
self [k] = ko.observable(item [k]);

self.total = ko.dependentObservable(function(){
return((self.quantity()* self.rate()));

} ).bind(个体);

self.tax_calc = ko.dependentObservable(function(){
return((self.tax_perc()* self.total())/ 100);

})。bind(self);
self.Tax_Total = ko.observable();

}
};

var quotationModel = new quotationViewModel(@ Html.Raw(@ Model.gridQuotationDetails));
ko.applyBindings(quotationModel,document.getElementById('divQuotationDetails'));

< / script>

解决方案

('#grandTax')。val(totalsum.toFixed( 2));

( '#totalAmt')VAL(totalsum.toFixed(2));

( '#TotalVat_Amt')。 VAL(tax.toFixed(2));
return totalsum.toFixed(2);
});

function item(item){
var self = this;
self.P055_ID = ko.observable('');
self.itemCode = ko.observable('');
self.itemDesc = ko.observable('');
self.packing = ko.observable();
self.VatCode = ko.observable();
self.VatDesc = ko.observable();
self.taxID = ko.observable();
self.tax_perc = ko.observable(0);
self.quantity = ko.observable(0);
self.rate = ko.observable(0);
self.remarks = ko.observable();

for(var k in item)
self [k] = ko.observable(item [k]);

self.total = ko.dependentObservable(function(){
return((self.quantity()* self.rate()));

} ).bind(个体);

self.tax_calc = ko.dependentObservable(function(){
return((self.tax_perc()* self.total())/ 100);

})。bind(self);
self.Tax_Total = ko.observable();

}
};

var quotationModel = new quotationViewModel(@ Html.Raw(@ Model.gridQuotationDetails));
ko.applyBindings(quotationModel,document.getElementById('divQuotationDetails'));

< / script>


grid have price, qty column. i need to calculate the total ie. price * qty. Its working new row only. but am fetching the data from web service and loaded it into the grid. now am chaning the qty value but the calculation is not working. its working adding a new row. Please help..

What I have tried:

<script>

        var quotationViewModel = function (quotations) {
            var self = this;

            self.quotations = ko.observableArray(ko.utils.arrayMap(quotations, function (item) {
                return new Item(item);
            }));

            self.addquotation = function () {
                self.quotations.push(new Item());

                UIValidation();
            };

            self.removequotation = function (quotation) {
                self.quotations.remove(quotation);
            };
            self.savequotation = function () {
                return ko.utils.stringifyJson(self.quotations);
            }
            self.grand_total = ko.computed(function () {
                var total = 0;
                for (var p = 0; p < self.quotations().length; ++p) {
                    total += self.quotations()[p].total();
                }
                return total.toFixed(2);
            });

            self.Tax_Total = ko.computed(function () {
                var tax = 0;
                for (var p = 0; p < self.quotations().length; ++p) {
                    tax += self.quotations()[p].tax_calc();
                }
                return tax.toFixed(2);
            });

            self.grandTax = ko.computed(function () {
                var tax = 0, sum = 0, totalsum = 0;
                for (var p = 0; p < self.quotations().length; ++p) {
                    tax += self.quotations()[p].tax_calc();
                    sum += self.quotations()[p].total();
                    totalsum = tax + sum;
                }
                $('#grandTax').val(totalsum.toFixed(2));
                $('#totalAmt').val(totalsum.toFixed(2));
                $('#TotalVat_Amt').val(tax.toFixed(2));
                return totalsum.toFixed(2);
            });

            function Item(item) {
                var self = this;
                self.P055_ID = ko.observable('');
                self.itemCode = ko.observable('');
                self.itemDesc = ko.observable('');
                self.packing = ko.observable();
                self.VatCode = ko.observable();
                self.VatDesc = ko.observable();
                self.taxID = ko.observable();
                self.tax_perc = ko.observable(0);
                self.quantity = ko.observable(0);
                self.rate = ko.observable(0);
                self.remarks = ko.observable();

                for (var k in item)
                    self[k] = ko.observable(item[k]);

                self.total = ko.dependentObservable(function () {
                    return ((self.quantity() * self.rate()));

                }).bind(self);

                self.tax_calc = ko.dependentObservable(function () {
                    return ((self.tax_perc() * self.total()) / 100);

                }).bind(self);
                self.Tax_Total = ko.observable();

            }
        };

        var quotationModel = new quotationViewModel(@Html.Raw(@Model.gridQuotationDetails));
        ko.applyBindings(quotationModel, document.getElementById('divQuotationDetails'));

    </script>

解决方案

('#grandTax').val(totalsum.toFixed(2));


('#totalAmt').val(totalsum.toFixed(2));


('#TotalVat_Amt').val(tax.toFixed(2)); return totalsum.toFixed(2); }); function Item(item) { var self = this; self.P055_ID = ko.observable(''); self.itemCode = ko.observable(''); self.itemDesc = ko.observable(''); self.packing = ko.observable(); self.VatCode = ko.observable(); self.VatDesc = ko.observable(); self.taxID = ko.observable(); self.tax_perc = ko.observable(0); self.quantity = ko.observable(0); self.rate = ko.observable(0); self.remarks = ko.observable(); for (var k in item) self[k] = ko.observable(item[k]); self.total = ko.dependentObservable(function () { return ((self.quantity() * self.rate())); }).bind(self); self.tax_calc = ko.dependentObservable(function () { return ((self.tax_perc() * self.total()) / 100); }).bind(self); self.Tax_Total = ko.observable(); } }; var quotationModel = new quotationViewModel(@Html.Raw(@Model.gridQuotationDetails)); ko.applyBindings(quotationModel, document.getElementById('divQuotationDetails')); </script>


这篇关于淘汰赛js网格ajax呼叫无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆