antd-日歷組件,前后禁止選擇,只能選中間一部分的實例
antd-日歷組件,前后禁止選擇,只能選中間一部分:
dateDisabledDate(current) { // 需求有效期的禁止選擇時間 if (this.state.sailingtimeValue != null && this.state.sailingtimeValue.length != 0) { return current && (current < moment().subtract(1, 'd').add(1, "M") || current > moment(this.state.sailingtimeValue[0]).subtract(1, 'd')); } else { return current && current < moment().subtract(1, 'd').add(1, "M") } }
補充知識:關(guān)于 Ant Design 中 Input 組件的 defaultValue 屬性的一個小問題
記錄關(guān)于一次 Ant Design 使用時遇到的一個問題,defaultValue屬性賦值,頁面交互操作處理數(shù)據(jù)之后頁面數(shù)據(jù)未更新(未按照預(yù)期顯示)。
class Component extends React.Component{ constructor(props) { super(props); this.state = { list: [ {name: 111}, {name: 222}, {name: 333}, ] }; } deal(index) { let {list} = this.state; list.splice(index, 1); this.setState({ list }); } render() { let {list} = this.state; return ( <span> <Button type="danger" onClick={this.deal.bind(this, index)}>刪除</Button> { list.map((item, index) => { <Row> <Col span={24}> <Item {...formItemLayout} label=" " colon={false}> <Input defaultValue={item.name} onChange={event => {this.nameChange(event, index)}} /> </Item> </Col> </Row> }) } </span> ); } }
頁面初始效果:
經(jīng)過 deal 方法處理之后的效果:
經(jīng)過多次嘗試,比如:
懷疑 splice 出了問題,因為工程中 splice 有很多庫的處理,經(jīng)過各種嘗試打印 splice 處理之后的數(shù)據(jù)結(jié)果,排除 splice 因素
嘗試 react-addons-update ,排除,
在 render 函數(shù)中打印結(jié)果,發(fā)現(xiàn)數(shù)據(jù)更新過了,費解…
在 render 中,通過 {item.name} 檢測數(shù)據(jù)變化,確定 span 顯示的數(shù)據(jù)已經(jīng)發(fā)生變化,最終確定結(jié)果:數(shù)據(jù)已經(jīng)更新,Input 顯示存在問題?。?!
……
經(jīng)過一段時間的思考,確認數(shù)據(jù)已經(jīng)更新,只是在顯示的時候出了問題,返回去查 antD 的 Input 文檔,發(fā)現(xiàn)了:
defaultValue 與 value 兩個相似的屬性,于是嘗試著 value 替代 defaultValue 最終解決問題。
以上這篇antd-日歷組件,前后禁止選擇,只能選中間一部分的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue項目如何設(shè)置全局字體樣式font-family
這篇文章主要介紹了vue項目如何設(shè)置全局字體樣式font-family問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11詳解vue-router數(shù)據(jù)加載與緩存使用總結(jié)
這篇文章主要介紹了詳解vue-router數(shù)據(jù)加載與緩存使用總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-10-10詳解mpvue實現(xiàn)對蘋果X安全區(qū)域的適配
這篇文章主要介紹了詳解mpvue實現(xiàn)對蘋果X安全區(qū)域的適配,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-07-07