Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sharepoint SPFX@pnp/sp v2.0.0 item.like不是一个函数_Sharepoint_Promise_Spfx_Pnp Js - Fatal编程技术网

Sharepoint SPFX@pnp/sp v2.0.0 item.like不是一个函数

Sharepoint SPFX@pnp/sp v2.0.0 item.like不是一个函数,sharepoint,promise,spfx,pnp-js,Sharepoint,Promise,Spfx,Pnp Js,我使用pnpjsv2.0.0和SPFX来实现一些列表操作 public async getitem(listname) { // get a specific item by id const item: any = await sp.web.lists.getByTitle(listname).items.getById(20).get(); console.log(item); // await item.like(); // get the like

我使用pnpjsv2.0.0和SPFX来实现一些列表操作

public async getitem(listname) {
    // get a specific item by id
    const item: any = await sp.web.lists.getByTitle(listname).items.getById(20).get();
    console.log(item);
    // await item.like();
    // get the liked by data
    const likedByData: ILikeData[] = await item.getLikedBy();
    console.log(likedByData);
    // get the liked by information
    const likedByInfo: ILikedByInformation = await item.getLikedByInformation();
    console.log(likedByInfo);
}
我获取了item对象,但无法向其添加类似项,我获取了错误:

Uncaught (in promise) TypeError: item.like is not a function

我使用了文档摘要:

首先:您是否正确引用和导入了所有内容?只是要求澄清,因为您提供的代码没有显示。以下是我们需要的:

import { sp } from "@pnp/sp";
import "@pnp/sp/comments/item";
import { ILikeData, ILikedByInformation } from "@pnp/sp/comments";
但我想你做对了

第二,也可能是更可能的问题:如果您仔细查看文档(您提供的链接),页面顶部会显示以下内容:

这些API目前处于测试阶段,可能会发生更改,或者可能无法在所有租户上运行


我在我的开发环境中测试了文档中的精确代码,但这也不起作用。因此,它可能对您的租户还不起作用。

首先:您是否正确引用和导入了所有内容?只是要求澄清,因为您提供的代码没有显示。以下是我们需要的:

import { sp } from "@pnp/sp";
import "@pnp/sp/comments/item";
import { ILikeData, ILikedByInformation } from "@pnp/sp/comments";
但我想你做对了

第二,也可能是更可能的问题:如果您仔细查看文档(您提供的链接),页面顶部会显示以下内容:

这些API目前处于测试阶段,可能会发生更改,或者可能无法在所有租户上运行

我在我的开发环境中测试了文档中的精确代码,但这也不起作用。所以它可能对你的房客还不起作用