antd 给select下拉框添加懒加载

给select下拉框添加属性

dropdownRender={menu => (
                                <div>
                                  {menu}
                                  <div
                                    className="selectScroll"
                                    style={{ textAlign: 'center' }}
                                    onMouseDown={e => e.preventDefault()}
                                  >
                                    {
                                      selectLoading && // 加载状态
                                        <Spin size="small" style={{ padding: '8px' }} />
                                    }
                                  </div>
                                </div>
                              )}
onFocus:
const index = document.getElementsByClassName('selectScroll').length;
      for (let i = 0; i < index; i++) {
        const node = document.getElementsByClassName('selectScroll')[i].previousElementSibling.children[0];
        node.onscroll = (e) => {
          const { pageTotal, selectLoading } = this.state; // 数据总条数,加载状态
          const { clientHeight, scrollHeight, scrollTop } = e.target;
          if ((clientHeight + scrollTop === scrollHeight) && !selectLoading) {
            this.setState({
              selectCurPage: this.state.selectCurPage + 1, // 页数加一
            }, () => {
              if (Math.ceil(pageTotal / 15) >= this.state.selectCurPage) { // 懒加载一次加载15条数据
                // 这里通过接口去获取数据
              }
            });
          }
        };
      }

猜你喜欢

转载自www.cnblogs.com/hamili/p/12168283.html
今日推荐