在 SPFx 中使用 Graph API 在共享点中创建列表项
create list item in sharepoint using Graph API in SPFx
我正在尝试使用 spfx react with 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
我希望将对象发布到联系人列表中。
示例测试演示供您参考。
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");
}
})
});
我正在尝试使用 spfx react with 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
我希望将对象发布到联系人列表中。
示例测试演示供您参考。
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");
}
})
});