【问题标题】:getting list items in SPFx application在 SPFx 应用程序中获取列表项
【发布时间】:2019-03-27 20:43:33
【问题描述】:

试图通过 SPFx webpart 项目中 spHttpClient 对象的 get 方法检索列表项。

这里是代码片段;

private readItems(): void {
    this.setState({
      status: 'Loading all items...',
      items: []
    });
    this.props.httpClient.get(`${this.siteUrl}/_api/web/lists/getbytitle('${this.props.listName}')/items?$select=Title,Id`, 
    SPHttpClientConfigurations.v1)
      .then((response: Response): Promise<{ value: IListItem[] }> => {
        debugger;
        return response.json();
      });
  }

这里触发的这个函数是来自服务器的响应;

消息很明显,但我确实需要获取此网址中的列表项。我怎样才能实现它?

我用 yeoman generator("yo @microsoft/sharepoint") 创建了这个项目,有什么配置可以让它运行 http:// 而不是 https://

如您所知,应用程序的默认地址是“https://localhost:4321/temp/workbench.html

【问题讨论】:

    标签: sharepoint


    【解决方案1】:

    如果您不部署租户,您将无法访问该租户。如果您将其部署到 SharePoint,这会将您的工作台与 SharePoint 链接起来。

    另一个选项是,如果您将使用本地工作台而不是 SharePoint 租户,则可以模拟您的列表。

    您可以观看此视频,了解如何模拟您的列表或将其部署到 SharePoint: https://www.youtube.com/watch?v=9VMwjb2pbQ8&index=3&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq

    【讨论】:

      【解决方案2】:

      您可以轻松使用租户的工作台:https://your_tenant_name.sharepoint.com/_layouts/15/workbench.aspx

      在这种情况下,您不需要模拟任何东西。 只需使用 gulp serve --nobrowser 并转到该网址。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-05-03
        • 2010-10-05
        • 2012-05-27
        • 1970-01-01
        • 2022-06-30
        • 1970-01-01
        • 2023-02-22
        相关资源
        最近更新 更多