Javascript 我想在getcolor函数传单js中进行条件返回

Javascript 我想在getcolor函数传单js中进行条件返回,javascript,leaflet,choropleth,Javascript,Leaflet,Choropleth,您好,我想制作分类图,我尝试在getcolor函数中制作条件图,但它不起作用,只显示一种颜色 这是我的密码 function openModal(e) { var t = e.target.feature.properties.url; $.getJSON("src/json/data-agregasi.json", function(e) { for (var a = e.length, o = 0; a > o; o++) e[o].url == t &am

您好,我想制作分类图,我尝试在getcolor函数中制作条件图,但它不起作用,只显示一种颜色

这是我的密码

function openModal(e) {
  var t = e.target.feature.properties.url;
  $.getJSON("src/json/data-agregasi.json", function(e) {
    for (var a = e.length, o = 0; a > o; o++)
      e[o].url == t &&
        (dataStatistik(e[o]),
        $("#namaKecamatan").text("Demografi Kependudukan & Pendidikan di Kecamatan " + e[o].kecamatan),
        $("#luasWilayah").text(e[o].luas_wilayah),
        $("#kawasan").text(e[o].kawasan),
        $("#populasi").text(e[o].ikg, 0, "."),
        $("#jumlahKelurahan").text(e[o].jumlah_kelurahan),
        $("#jumlahSD").text(accounting.formatNumber(e[o].jml_sd, 0, ".")),
        $("#jumlahSMP").text(accounting.formatNumber(e[o].jml_smp, 0, ".")),
        $("#jumlahSMA").text(accounting.formatNumber(e[o].jml_sma, 0, ".")),
        $("#jumlahSMK").text(accounting.formatNumber(e[o].jml_smk, 0, ".")),
        $("#jumlahKeaksaraan").text(accounting.formatNumber(e[o].jml_keaksaraan, 0, ".")),
        $("#usiaSD").text(accounting.formatNumber(e[o].umur_7_12, 0, ".")),
        $("#usiaSMP").text(accounting.formatNumber(e[o].umur_13_15, 0, ".")),
        $("#usiaSMA").text(accounting.formatNumber(e[o].umur_16_18, 0, ".")),
        $("#jumlahPtkSD").text(accounting.formatNumber(e[o].jml_ptk_sd, 0, ".")),
        $("#jumlahPtkSMP").text(accounting.formatNumber(e[o].jml_ptk_smp, 0, ".")),
        $("#jumlahPtkSMA").text(accounting.formatNumber(e[o].jml_ptk_sma, 0, ".")),
        $("#jumlahPtkSMK").text(accounting.formatNumber(e[o].jml_ptk_smk, 0, ".")),
        $("#jumlahPtkKeaksaraan").text(accounting.formatNumber(e[o].jml_ptk_keaksaraan, 0, ".")),
        $("#jumlahPdSD").text(accounting.formatNumber(e[o].jml_pd_sd, 0, ".")),
        $("#jumlahPdSMP").text(accounting.formatNumber(e[o].jml_pd_smp, 0, ".")),
        $("#jumlahPdSMA").text(accounting.formatNumber(e[o].jml_pd_sma, 0, ".")),
        $("#jumlahPdSMK").text(accounting.formatNumber(e[o].jml_pd_smk, 0, ".")),
        $("#jumlahPdKeaksaraan").text(accounting.formatNumber(e[o].jml_pd_keaksaraan, 0, ".")));
  }),
    $("#statsModal").modal("show"),
    e.target.getBounds();
}

function getColor(e) {
  if (e > 20 && e.luas_wilayah < 6000) {
    return "#99000d";
  } else {
    return "#deebf7";
  }
}

如果不进一步实现和同时实现一个对象,就不能有一个基元值

if (e > 20 && e.luas_wilayah < 6000) {
最简单的方法是,使用单个数字并检查值是否在所需范围内

function getColor(e) {
    return e > 20 && e < 6000
        ? "#99000d"
        : "#deebf7"
}

请添加e。但我要比较的变量不同。请将此变量添加到问题中。