【问题标题】:create list item in sharepoint using Graph API in SPFx在 SPFx 中使用 Graph API 在 sharepoint 中创建列表项
【发布时间】:2020-06-16 10:59:26
【问题描述】:

我正在尝试使用 spfx 与 Graph API 反应在 sharepoint 中的现有列表中创建一个新列表项。

 const obj: string = JSON.stringify({
      'LinkTitle': `Item ${new Date()}`,
      'Contactlist': '555555555',
      'CompanyName': 'dfvb',
      'Country': 'asd'
    });

  this.props.context.msGraphClientFactory
      .getClient()
      .then((client: MSGraphClient): void => {
        // get information about the current user from the Microsoft Graph
        client
          .api("sites('root')/lists('Contactlist')/items")
          .post(obj).then(() => {
            console.log('obj' + obj);
          });
      });

但它发布了一个没有值的列表项。

sharepoint list item with no values

我希望将 obj 发布到联系人列表中。

【问题讨论】:

    标签: sharepoint


    【解决方案1】:

    示例测试演示供您参考。

    const obj: string = JSON.stringify(
      {
        "fields": {
          'Title': 'Lin',
          'Company': 'Microsoft'
        }
      }
      );
    this.props.context.msGraphClientFactory
      .getClient()
      .then((client: MSGraphClient): void => {
        client         
         .api("/sites/siteid/lists/77d9ee4c-9142-40d1-8edb-9bdfd226be2a/items")
         .header('Content-Type','application/json')
         .version("v1.0")
          .post(obj, (err, res, success) => {
            if (err) {  
            console.log(err);                 
            }                
            if (success)
            {
              console.log("success");
            }            
          })
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-25
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多