做moment().format()
回报2018-05-30T11:38:04+10:00
。
我怎样才能只检索2018-05-30
它的一部分?
从下面的内容中,我如何获得具有最高价值的元组?
Array[(String, Int)] = Array((a,30),(b,50),(c,20))
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我想要的结果是 (b,50)
我有以下代码:
$("#test").on("keyup", (e) => {
if(e.target.value.length === 3) {
setTimeout(() => {
console.log("fired")
}, 2000)
}
})
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="test">
Run Code Online (Sandbox Code Playgroud)
如果用户输入3个字符,则console.log("fired")
在2秒后自动触发(使用上述代码)
但是如果用户在此期间键入另一个角色,我需要能够清除旧时间并再次等待2秒.
一旦超时,它应该按预期运行.我怎样才能做到这一点?
编辑:
let timeOut;
$("#test").on("keyup", (e) => {
if(e.target.value.length === 3) {
timeOut = setTimeout(() => {
console.log("fired if length is 3")
}, 2000)
} else if (e.target.value.length === 4) {
clearTimeout(timeOut)
timeOut = setTimeout(() => {
console.log("fired if length is 4")
}, 2000)
}
})
Run Code Online (Sandbox Code Playgroud) 我有一个带有div的组件,该组件接受onClick和禁用aria的属性。他们两个都是道具,残疾人是可选的。在我的渲染方法中,执行以下操作:
<div onClick={!this.props.Disabled ? this.props.Click : undefined}
aria-disabled={this.props.Disabled>My Div</div>
Run Code Online (Sandbox Code Playgroud)
我使用CSS可视化了禁用状态(不透明度:0.5,指针事件:none blah blah)。但是我想知道是否有更好的方法来处理实际的onClick。由于它是强制性道具,因此即使禁用该项目,您仍然需要传递onClick来满足条件。有没有更好的方法来解决这个问题?
我正在尝试测试是否将正确的道具传递给组件。在酶中,它很容易通过:
const control = enzyme.mount(<Test />);
expect(control.find(<CompToTest />).props().MyProp).toEqual(expectedProp);
Run Code Online (Sandbox Code Playgroud)
如何使用 react-testing-library 获得相同的结果?谢谢。
javascript ×3
html ×2
reactjs ×2
apache-spark ×1
css ×1
datetime ×1
enzyme ×1
jquery ×1
momentjs ×1
scala ×1