从大表中根据两个用户输入获取数值

huangapple go评论75阅读模式
英文:

How to get a value from big table based on two user inputs

问题

我想制作一个React Native应用,帮助火车司机计算如何使用停车制动器。我有一个大表格,其中有两个变量(火车在列上的重量和在行上的角度,火车必须停放的位置)。用户输入这些值,表格中应显示正确的制动力量。

如果我使用if语句来做这个,将会花费太长时间并可能会出现问题。使用case语句也一样。有没有关于如何使用JavaScript来实现这个的想法?

我尝试过使用数据库,但它将需要比“if”语句更多的代码,因为这些不是唯一的变量。所以我没有其他想法应该如何做。这是表格,我有两个类似的

英文:

i want to make an React native app that help train driver calculate how they shoul use parking break. I have this big table where you have to variable (how much the train wight on column and the angle on row, where the train has to be parked). So the user input the values and the right amount of forced from table should be shown.
If i would do that with if statements this will take too long and may case problems.Same with case statements. Any ideas how could i do that with JavaScript?

I triend with Database and it will require even more code than 'if' statemens, sience those are not the only variables. So i have no other ideas how should i do that. This is the table, i have two of these

答案1

得分: 0

你需要首先创建一个用于保存表格数据的对象,就像这样:

let data = {
    "2.5%<24h": {
        "40t": 1,
        "80t": 2,
        "100t": 3
        // 等等。
    },
    "2.5%>24h": {
        "40t": 2,
        "80t": 4,
        "100t": 5
        // 等等。
    },
    "3%": {
        "40t": 3,
        "80t": 5,
        "100t": 6
        // 等等。
    }
    // 等等。
};

你可以将它存储在与你的其余代码分开的文件中,然后将其导入到你的代码中。

当你想要访问这些数据时,你可以按照适当的列和行进行访问,就像这样:

data["3%"]["80t"]

这将给你 5。

英文:

You need to first build an Object to hold the table data, like this:

let data = {
    &quot;2.5%&lt;24h&quot;: {
        &quot;40t&quot;: 1,
        &quot;80t&quot;: 2,
        &quot;100t&quot;: 3
        // etc.
    },
    &quot;2.5%&gt;24h&quot;: {
        &quot;40t&quot;: 2,
        &quot;80t&quot;: 4,
        &quot;100t&quot;: 5
        // etc.
    },
    &quot;3%&quot;: {
        &quot;40t&quot;: 3,
        &quot;80t&quot;: 5,
        &quot;100t&quot;: 6
        // etc.
    }
    // etc.
};

You can store it in a separate file from the rest of your code and import it into your code.

When you want to access this data you go to the appropriate column and row, like this:

data[&quot;3%&quot;][&quot;80t&quot;]

This will give you 5.

huangapple
  • 本文由 发表于 2023年2月7日 03:12:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75365615.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定