需要0与null不同

时间:2021-12-24 22:25:02

Here's my code in this div tag:

这是我在div标签中的代码:

<div className="lk-btn-group btn-group clear">
            {this.state.invoiceId ? <button className="btn btn-primary btn-sm pull-left" onClick={() => this.printInvoice()}>{abp.localization.localize('PrintInvoice')}</button> : null}
            {this.state.delivery.delivery && !this.state.invoiceId ? <button className="btn btn-primary btn-sm pull-left" onClick={() => this.printDeliveryNote()}>{abp.localization.localize('PrintDeliveryNote')}</button> : null}
            {this.state.delivery.delivery == null ? <button className="btn btn-primary btn-sm pull-right" onClick={() => {
             this.markAsDelivered()
            }} disabled={!this.state.beginningPercentage || !this.state.gallonsDelivered}>{this.props.completeDelivery}</button> : <span className="label label-default pull-right"><i className="fa fa-check"></i> {this.props.deliveryComplete}</span>} 
</div>

My question is how do I get an input of 0 (zero) to not be the same as null? I need the ability for the user to go ahead and put a 0 and have my disabled button show rather than be disabled. I believe it's happening at the == null in the fourth line of the div code above, which appears to me to disable the "btn btn-primary btn-sm pull right"

我的问题是如何获得0(零)的输入与null不相同?我需要能够让用户继续前进并输入0并禁用我的禁用按钮而不是禁用。我相信它发生在上面div代码第四行的== null,在我看来禁用“btn btn-primary btn-sm pull right”

That's fine if the user hasn't entered anything yet, but I also need the 0 to be treated as any other value entered and not just null or empty if that makes sense. I still need all the other functionality to remain the same.

如果用户还没有输入任何内容,那就没问题了,但是我还需要将0视为输入的任何其他值,如果有意义的话,不仅仅是null或空。我仍然需要所有其他功能保持不变。

1 个解决方案

#1


0  

I found this, I hope it helps you, essentially you can use typeof to check the type of this.state.delivery.delivery

我找到了这个,我希望它可以帮助你,基本上你可以使用typeof来检查this.state.delivery.delivery的类型

// typeof this.state.delivery.delivery is a number
if (typeof this.state.delivery.delivery === "number")

This answer expands on this principle. https://*.com/a/4514622/6558939

这个答案扩展了这一原则。 https://*.com/a/4514622/6558939

You could also try Number.isInteger(typeof this.state.delivery.delivery) which should return true or false satisfying the ternary operator.

您也可以尝试Number.isInteger(typeof this.state.delivery.delivery),它应返回true或false,以满足三元运算符。

#1


0  

I found this, I hope it helps you, essentially you can use typeof to check the type of this.state.delivery.delivery

我找到了这个,我希望它可以帮助你,基本上你可以使用typeof来检查this.state.delivery.delivery的类型

// typeof this.state.delivery.delivery is a number
if (typeof this.state.delivery.delivery === "number")

This answer expands on this principle. https://*.com/a/4514622/6558939

这个答案扩展了这一原则。 https://*.com/a/4514622/6558939

You could also try Number.isInteger(typeof this.state.delivery.delivery) which should return true or false satisfying the ternary operator.

您也可以尝试Number.isInteger(typeof this.state.delivery.delivery),它应返回true或false,以满足三元运算符。