【问题标题】:SPFx ListView control - "defaultSelection" does not workSPFx ListView 控件-“defaultSelection”不起作用
【发布时间】:2021-06-10 01:31:53
【问题描述】:

我正在使用来自 @pnp/spfx-controls-react 库版本 2.5.0 的 ListView 控件

有一个记录在案的属性称为defaultSelection,它是:

默认选择项的索引

我正在尝试像这样使用它来自动选择表格的第一行:

          <ListView
            items={this.state.items}
            viewFields={this._viewFields}
            selectionMode={SelectionMode.single}
            selection={this._updateSelectedItems}
            defaultSelection={[0]}
          />

但是当页面加载时它永远不会选择任何东西。控制台中也没有错误。

我还使用了一个在这里找到的简单示例:https://github.com/RaspeR87/sp-dev-fx-webparts/tree/master/spfx-react-controls/ListView 在一个简单的项目中尝试它,但它再次没有选择任何东西。

有没有人设法利用这个属性?每一个输入都表示赞赏。

【问题讨论】:

    标签: reactjs listview sharepoint-online web-parts spfx


    【解决方案1】:

    是的,我的测试结果和你一样。您可以在 PNP 反应控制 Github 存储库中发布此问题。https://github.com/pnp/sp-dev-fx-controls-react/issues

    【讨论】:

      【解决方案2】:

      这是解决问题的技巧:

      // Add a useRef to your ListView control
      const refListView = useRef<any>(null);
      
      // Set selection on load
      useEffect(() => {
             
          // Set mySelection as default selection
          const mySelection = [1,4,6];
          mySelection.forEach(i => {
              setTimeout(() => {
                  refDocs.current._selection.setIndexSelected(i, true, false);
              }, 0);
          });
      
      }, []);
      
      // ListView control
      <ListView ref={refListView }...
      

      【讨论】:

        猜你喜欢
        • 2021-10-29
        • 2013-12-11
        • 2017-07-07
        • 2014-07-28
        • 2017-01-28
        • 2014-04-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多