首页 > 解决方案 > 如果 SPFX PNP ListView 被隐藏并在 Modern 页面上再次显示,则无法在页面上加载

问题描述

我有我放置在渲染部分的列表视图,页面加载我通过 div 内的 j 查询隐藏它,当我显示它时没有数据出现在它上面,但是如果我点击开发工具它开始出现或者如果我改变它开始出现的屏幕分辨率。这很奇怪。

<ListView
items={this.state.supplierContractItems.slice(this.state.supplierContractRare, this.state.supplierContractFront + 1)}
showFilter={this.state.showFilters}
viewFields={this.state.supplierContractViewFields}
selectionMode={SelectionMode.multiple}
selection={this.getSupplierContractSelection}
filterPlaceHolder="Search..." />

标签: sharepointsharepoint-onlinespfx

解决方案


FIRSTLY THANKS A LOT  TO INVESTIGATE ON THIS, JUST TRY THE BELOW CODE, THIS WILL FIRST HIDE THE LIST VIEW ON PAGE LOAD AND THEN BUTTON IS CLICKED TO SHOW BACK, IT ONLY SHOWS THE SEARCH BUTTON NOT THE RESULT, BUT JUST IF YOU`enter code here` CHANGE THE RESOLUTION OF THE SCREEN BY PRESSING CTRL + Mouse wheel up/down the result will show automatically. 


  export default class Reacttest extends React.Component<IReacttestProps, IHelloWorldState, {}> {

  constructor(props: IReacttestProps) {

    super(props)

    this.state = {
      items: [],
      selecteduser: []
    };

    sp.setup({
      spfxContext: this.props.context
    });

    this.handle = this.handle.bind(this);
  }





  public render(): React.ReactElement<IReacttestProps> {
const viewFields: IViewField[] = [{
      name: "Title",
      displayName: "Title",
      isResizable: true,
      sorting: true,
      minWidth: 0,
      maxWidth: 150
    },
    {
      name: "ID",
      displayName: "ID",
      isResizable: true,
      sorting: true,
      minWidth: 0,
      maxWidth: 200
    }];
    return (
      <div >
        <span id="listView_id">
          <ListView
            items={this.state.items}
            viewFields={viewFields}
            iconFieldName="ServerRelativeUrl"
            compact={true}
            selectionMode={SelectionMode.multiple}
            selection={this._getSelection}
            showFilter={true}
            filterPlaceHolder="Search..."
          />
        </span>
        <span>  <input type="button" value="Click To Show" onClick={this.handle} /></span>
      </div>
    );
  }
  componentDidMount() {
    sp.web.lists.getByTitle("People").items.top(5).get().then(items => {
      console.log(items)
      this.setState({ items })
    });
    $("#listView_id").hide();
  }
  private handle() {
    $("#listView_id").show();
  }
  private _getSelection(items: any[]) {
    console.log('Items:', items);
  }
}

推荐阅读