antd inputnumber:执行函数onchangecomplete而不是onchange

发布于 2025-01-26 22:20:36 字数 522 浏览 2 评论 0原文

<Form.Item
        label="Amount"
        name={[index, 'amount']}
      >
        <InputNumber
          style={{ width: '100%' }}
          min={1}
          // onChange={() => {
          //   const array = [...form.getFieldValue('bankAccount')]
          //   setCurrentAccountArray(array)
          // }}
        />
      </Form.Item>

在上面的代码中,您可以看到我正在强行更新CurrentAccountarray的状态, 我想在值完全更改而不是onchange之后执行此操作,该值在每个密钥按下都执行...

有什么方法可以实现这一目标吗?我不想使用Onenterpressed。

<Form.Item
        label="Amount"
        name={[index, 'amount']}
      >
        <InputNumber
          style={{ width: '100%' }}
          min={1}
          // onChange={() => {
          //   const array = [...form.getFieldValue('bankAccount')]
          //   setCurrentAccountArray(array)
          // }}
        />
      </Form.Item>

in the code above you can see that I am forcefully updating the state of currentAccountArray,
I want to execute this after the value is completely changed instead of onChange, which executes on every key press...

is there a way I can achieve this? I do not want to use onEnterPressed.

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

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

发布评论

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

评论(1

二智少女猫性小仙女 2025-02-02 22:20:36

也许使用输入而不是onchange?
- 或者 -
也许封闭的延迟电话?

function setCurrentAccountArray(arr){
    // whatever your doing here
    console.log("hi", arr)
}

var TO_later;
function delayedCall(fn, arg, delay){
    clearTimeout(TO_later);
    TO_later = setTimeout((function(Vfn, Varg){
        return function(){
            Vfn(Varg);
        }
    })(fn, arg), delay);
}

<Form.Item
    label="Amount"
    name={[index, 'amount']}
>
<InputNumber
    style={{ width: '100%' }}
    min={1}
    onChange={() => {
        const array = [...form.getFieldValue('bankAccount')]
        delayedCall(setCurrentAccountArray, array, 300)
    }}
/>
</Form.Item>

Maybe use onInput instead of onChange?
-- OR --
Maybe a delayed call wrapped in a closure?

function setCurrentAccountArray(arr){
    // whatever your doing here
    console.log("hi", arr)
}

var TO_later;
function delayedCall(fn, arg, delay){
    clearTimeout(TO_later);
    TO_later = setTimeout((function(Vfn, Varg){
        return function(){
            Vfn(Varg);
        }
    })(fn, arg), delay);
}

<Form.Item
    label="Amount"
    name={[index, 'amount']}
>
<InputNumber
    style={{ width: '100%' }}
    min={1}
    onChange={() => {
        const array = [...form.getFieldValue('bankAccount')]
        delayedCall(setCurrentAccountArray, array, 300)
    }}
/>
</Form.Item>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文