【发布时间】:2016-04-27 11:30:23
【问题描述】:
我想创建包装费计算器。 我创建了几个滑块。有高度、宽度、长度和重量滑块。用户设置所有滑块后,我想从数组中检索费用。 最好的方法是什么?
链接到带有数据的表:https://services.amazon.co.uk/services/fulfilment-by-amazon/pricing.html
链接到我的工具:http://tests.uk4u.pl/amazonProfitCalc/
我做了什么:
var slider_length_value = $(".slider-length").slider("value");
var slider_width_value = $(".slider-width").slider("value");
var slider_height_value = $(".slider-height").slider("value");
var slider_weight_value = $(".slider-weight").slider("value");
var fullfilmentFee = Array({
"packaging": "Small Envelope",
"length": "20",
"width": "15",
"height": "1",
"weight": "100",
"fee": "1.07"
},
{
"packaging": "Standard Envelope",
"length": "33",
"width": "23",
"height": "2.5",
"weight": "100",
"fee": "1.19"
}, {
"packaging": "Standard Envelope",
"length": "33",
"width": "23",
"height": "2.5",
"weight": "250",
"fee": "1.31"
}, {
"packaging": "Standard Envelope",
"length": "33",
"width": "23",
"height": "2.5",
"weight": "500",
"fee": "1.51"
},
{
"packaging": "Large Envelope",
"length": "33",
"width": "23",
"height": "5",
"weight": "1000",
"fee": "1.70"
},
{
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "250",
"fee": "1.66"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "500",
"fee": "1.72"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "1000",
"fee": "1.77"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "1500",
"fee": "2.19"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "2000",
"fee": "2.41"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "3000",
"fee": "3.30"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "4000",
"fee": "3.40"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "5000",
"fee": "3.40"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "6000",
"fee": "3.45"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "7000",
"fee": "3.45"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "8000",
"fee": "3.53"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "9000",
"fee": "3.53"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "10000",
"fee": "3.53"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "11000",
"fee": "3.53"
}, {
"packaging": "Standard Parcel",
"length": "45",
"width": "34",
"height": "26",
"weight": "12000",
"fee": "3.54"
}
);
var fee = $.map(fullfilmentFee, function(value, key) {
if (value.length == "33") {
//return value.fee;
return value.fee;
} else {
$(".message").html("Error!!!");
}
});
//console.log(price);
//output: $220
$(".message").html(fee);
编辑:
也许再一次。用户准备包装并使用滑块设置此包装的长度宽度高度和重量。接下来,他按下提交按钮并获得与这些尺寸和重量相对应的履行费用。如果所有的暗淡都与数组中的完全一样,那就很容易了,但是:
-
如何在数组中的数字之间创建条件,例如 between
履行[0].length和履行[1].length
如果一个或多个变量(长度或宽度或高度或重量)的值高于正常范围,我想获得与该值相对应的费用。
对我的英语表示敬意和抱歉
【问题讨论】: