英文:
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 = {
"2.5%<24h": {
"40t": 1,
"80t": 2,
"100t": 3
// etc.
},
"2.5%>24h": {
"40t": 2,
"80t": 4,
"100t": 5
// etc.
},
"3%": {
"40t": 3,
"80t": 5,
"100t": 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["3%"]["80t"]
This will give you 5.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论