gpt4 book ai didi

javascript - 在 rails4 中的 js 中调用配置变量

转载 作者:行者123 更新时间:2023-11-29 17:55:21 25 4
gpt4 key购买 nike

你好,我已经包含给定的文件 config/countries.rb

Shipping_10_14_days = ["AD", "AF", "AL", "AM", "AS", "AW", "AZ", "BA", "BB", "BM", "BS", "BZ", "CM", "CU", "CV", "DM", "DZ", "EE", "FK", "FM", "FO", "GF", "GL", "GY", "IS", "JM", "KG", "KY", "KZ", "LB", "LC", "LI", "LT", "MQ", "MU", "MV", "NA", "NU", "PA", "PF", "PY", "RO", "SV", "TD", "UA", "UG", "UZ", "ZM"]
Shipping_4_5_days = ["AE", "BD", "BH", "IR", "JO", "JP", "KH", "KW", "LA", "LK", "MM", "MO", "NF", "OM", "PH", "PK", "QA", "SA", "IN", "VN"]
Shipping_4_7_days = ["DK", "AT", "VI", "GB", "US"]
Shipping_5_7_days = ["BA", "BE", "BG", "CH", "CR", "CY", "CZ", "DE", "EG", "ES", "FI", "FR", "GE", "GH", "GL", "GR", "HN", "HR", "HU", "IE", "IL", "IT", "LU", "LV", "MA", "MC", "MN", "MT", "NA", "NC", "NG", "NL", "NO", "PL", "PT", "SE", "SK", "TR", "TW", "TZ", "ZA", "SG"]
Shipping_3_5_days = ["AU"]
Restricted_Country = ["AR", "BN", "BR", "BS", "CL", "CN", "CO", "CR", "EC", "FK", "GP", "GT", "GU", "ID", "IS", "MP", "MX", "NZ", "PE", "PM", "RS", "RU", "TH", "TT", "UY"]

现在我想在我的 app/assets/javascripts/test.js 中调用这些变量请指导我如何调用这些变量

function checkShippingDays(countryValue) {
var Shipping_10_14_days = ["AD", "AF", "AL", "AM", "AS", "AW", "AZ", "BA", "BB", "BM", "BS", "BZ", "CM", "CU", "CV", "DM", "DZ", "EE", "FK", "FM", "FO", "GF", "GL", "GY", "IS", "JM", "KG", "KY", "KZ", "LB", "LC", "LI", "LT", "MQ", "MU", "MV", "NA", "NU", "PA", "PF", "PY", "RO", "SV", "TD", "UA", "UG", "UZ", "ZM"]
var Shipping_4_5_days = ["AE", "BD", "BH", "IR", "JO", "JP", "KH", "KW", "LA", "LK", "MM", "MO", "NF", "OM", "PH", "PK", "QA", "SA", "IN", "VN"]
var Shipping_4_7_days = ["DK", "AT", "VI", "GB", "US"]
var Shipping_5_7_days = ["BA", "BE", "BG", "CH", "CR", "CY", "CZ", "DE", "EG", "ES", "FI", "FR", "GE", "GH", "GL", "GR", "HN", "HR", "HU", "IE", "IL", "IT", "LU", "LV", "MA", "MC", "MN", "MT", "NA", "NC", "NG", "NL", "NO", "PL", "PT", "SE", "SK", "TR", "TW", "TZ", "ZA", "SG"]
var Shipping_3_5_days = ["AU"]
var Restricted_Country = ["AR", "BN", "BR", "BS", "CL", "CN", "CO", "CR", "EC", "FK", "GP", "GT", "GU", "ID", "IS", "MP", "MX", "NZ", "PE", "PM", "RS", "RU", "TH", "TT", "UY"]

if ($.inArray(countryValue, restrictedCountry) > -1) {
alert('we don not ship in this country')
$('.adress-next').prop('disabled', true);
} else{
$('.adress-next').prop('disabled', false);
if ($.inArray(countryValue, shipping10to14) > -1) {
$('.shipping-days').html('<strong>FREE</strong> Delivery (average 10-14 business days)')
} else if ($.inArray(countryValue, shipping4to7) > -1) {
$('.shipping-days').html('<strong>FREE</strong> Delivery (average 4-7 business days)')
} else if ($.inArray(countryValue, shipping4to5) > -1) {
$('.shipping-days').html('<strong>FREE</strong> Delivery (average 4-5 business days)')
} else if ($.inArray(countryValue, shipping3to5) > -1) {
$('.shipping-days').html('<strong>FREE</strong> Delivery (average 3-5 business days)')
} else if ($.inArray(countryValue, shipping5to7) > -1) {
$('.shipping-days').html('<strong>FREE</strong> Delivery (average 5-7 business days)')
} else {
$('.shipping-days').html('<strong>FREE</strong> Delivery (average 4-7 business days)')
};
};
};

我需要在 js 文件中调用这些变量。

最佳答案

创建test.js.erb文件并使用

var Shipping_10_14_days  = <%= Shipping_10_14_days %>

关于javascript - 在 rails4 中的 js 中调用配置变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39636893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com