簡體   English   中英

從 web 部件組件 (spfx-reactjs) 調用 SharePoint 添加新的 webpart function

[英]call SharePoint's add new webpart function from within a web part component (spfx-reactjs)

我只是 reactjs-spfx 控件的新手。 我有一個列出所有頁面及其內容的 pnpjs 控件。 我應該能夠使用 web 部分添加編輯和刪除頁面。 我想在該組件中包含在編輯頁面內容時將新的 Web 部分添加到頁面內容的功能。 您如何從 SharePoint 調用該功能來添加新的 Web 部件? 請看下圖。 謝謝。 在此處輸入圖像描述

我建議為此使用 pnpjs 庫,它用一個漂亮的 api 包裝了大多數基本任務。我將自己的 webpart 添加到這樣的頁面,只是為了給你一個想法:

參見https://pnp.github.io/pnpjs/sp/clientside-pages/

const sp = SPFI(...)

// or get the existing page
const page = await sp.web.addClientsidePage(fileName, title);
const section = page.addSection();

const partDefs = await sp.web.getClientsideWebParts();

// find the web part we want to add by guid
const myPartDef = partDefs.find(c => areGuidsEqual(c.Id, MY_GUID));

const part = ClientsideWebpart.fromComponentDef(myPartDef);
part.setProperties({
  someProp: someValue
});

section.addControl(part);
await page.save();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM