我试图在我的ItemsKeyMapping.js中创建一个函数,该函数将计算客户将在产品上节省的百分比。我是javascript新手,一直在使用教程。这就是我所拥有的:
// @property _DiscountPercent calculates the percentage between customers price and MSRP
, _DiscountPercent: function (item)
{
var attributes = item.get('onlinecustomerprice') || ('pricelevel15');
if ((pricelevel15 != 0) && (onlinecustomerprice != 0))
{
DiscountPercent = (1 - pricelevel15 / onlinecustomerprice) * 100;
}
else
{
DiscountPercent = null;
}
return 'DiscountPercent';
}
熟悉SCA Mont Blanc的人可以帮助我完成此任务吗?谢谢。
最佳答案
尝试这个:
, _DiscountPercent: function (item)
{
var normalPrice= item.get('onlinecustomerprice')
var discountedPrice= item.get('pricelevel15');
var DiscountPercent = null;
if ((discountedPrice > 0) && (normalPrice > 0))
{
DiscountPercent = (1 - discountedPrice / normalPrice) * 100;
}
return DiscountPercent;
}