需要帮助比较从表单提交agaisnt生成的对象先前提交的对象

发布于 2025-02-06 03:00:58 字数 540 浏览 2 评论 0原文

因此,我正在构建一个数据收集软件,该软件在很大程度上依赖表单和表单验证。我目前已经使用formik和yup建立了动态​​表单,并通过个人验证进行了验证,但是我希望深入研究用户当前输入agaisnt先前的输入,以确保基于表单的对象的相同键的值逐渐增加或减少设置。

const ObjOne = 
{
   NumberOne: 100,
   NumberTwo: 200,
   NumberThree: 300,
}
const ObjTwo = 
{
   NumberOne: 150,
   NumberTwo: 250,
   NumberThree: 350,
}

我想设置某种系统来比较这两个对象,以验证用户当前提交numberOne对象两个中的提交是否适当地比对象一个。如果所述值不增加,则将返回错误,告诉用户数据无效。

如果有人可以帮助我集思广益,以实现这一目标或将我指向正确的方向,我将非常感谢它。

So I am building a data collection software that relies heavily on forms and form validations. I have currently built up dynamic forms with Formik and Yup with individual validation but im looking to dive deeper into validating the users current input agaisnt a previous input to make sure the value of the same key from the objects are incrementing or decrementing based on the form settings.

const ObjOne = 
{
   NumberOne: 100,
   NumberTwo: 200,
   NumberThree: 300,
}
const ObjTwo = 
{
   NumberOne: 150,
   NumberTwo: 250,
   NumberThree: 350,
}

I want to setup some sort of system to compare these two objects to validate that the users current submission for NumberOne in Object Two is properly incrementing higher than the previous value in Object One. If said value is not incrementing then it would return an error telling the user the data is not valid.

If someone could help me brainstorm on how to acheive this or point me in the proper direction i would greatly appreciate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

锦爱 2025-02-13 03:00:59

在您的示例中,您可以执行一个基本函数,该功能比较numberOne值:

const ObjOne = 
{
   NumberOne: 100,
   NumberTwo: 200,
   NumberThree: 300,
}
const ObjTwo = 
{
   NumberOne: 150,
   NumberTwo: 250,
   NumberThree: 350,
}

const check = (one, two) => {
if (two.NumberOne > one.NumberOne)
    console.log('ok');
else
    console.log('ko');
}

check(ObjOne, ObjTwo);

在此示例中,仅比较numberOne值,但您可以执行更复杂的功能来检查所有键。此示例只需回答您的特定问题。

这为给定的示例提供了工作:

const check = (one, two) => {
if (two.NumberOne < one.NumberOne || two.NumberTwo < one.NumberTwo || two.NumberThree < one.NumberThree)
    console.log('ko');
else
    console.log('ok');
}

With your example, you can do a basic function which compare NumberOne values:

const ObjOne = 
{
   NumberOne: 100,
   NumberTwo: 200,
   NumberThree: 300,
}
const ObjTwo = 
{
   NumberOne: 150,
   NumberTwo: 250,
   NumberThree: 350,
}

const check = (one, two) => {
if (two.NumberOne > one.NumberOne)
    console.log('ok');
else
    console.log('ko');
}

check(ObjOne, ObjTwo);

In this example, only NumberOne values are compared but you can do a more complicated function to check all keys. This example just answer to your specific question.

This does the job for the given example:

const check = (one, two) => {
if (two.NumberOne < one.NumberOne || two.NumberTwo < one.NumberTwo || two.NumberThree < one.NumberThree)
    console.log('ko');
else
    console.log('ok');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文