首页 > 解决方案 > 使用 Add-PnPClientSideWebPart 添加天气 WebPart 未设置位置

问题描述

我正在尝试在 SharePoint Online 的新式页面上添加天气 WebPart。

这是我正在执行的 PowerShell:

$jsonProperties = '
{
    "serverProcessedContent": {
        "searchablePlainTexts": {
            "webPartTitle": "Weather"
        }
    },
    "properties": {
        "temperatureUnit": "C",
        "locations": [
            {
                "countryName": "Australia",
                "name": "Manjimup, Australia",
                "latitude": -34.24055862426758,
                "longitude": 116.14610290527344,
                "showCustomizedDisplayName": false
            },
            {
                "countryName": "Australia",
                "name": "Bega, Australia",
                "latitude": -36.673919677734378,
                "longitude": 149.84178161621095,
                "showCustomizedDisplayName": false
            }
        ]
    }
}'

Add-PnPClientSideWebPart -Page https://mysharepointsite.sharepoint.com/Sites/MyPage -DefaultWebPartType Weather -WebPartProperties $jsonProperties

正在添加 WebPart,但没有天气位置,如下所示。

天气 WebPart

对于要添加到 WebPart 的位置,我缺少什么?

标签: powershellsharepointsharepoint-online

解决方案


我错过了财产"dataVersion": "1.2"。完整的 JSON 如下所示:

$jsonProperties = '
{
    "dataVersion": "1.2",
    "serverProcessedContent": {
        "searchablePlainTexts": {
            "webPartTitle": "Weather"
        }
    },
    "properties": {
        "temperatureUnit": "C",
        "locations": [
            {
                "countryName": "Australia",
                "name": "Manjimup, Australia",
                "latitude": -34.24055862426758,
                "longitude": 116.14610290527344,
                "showCustomizedDisplayName": false
            },
            {
                "countryName": "Australia",
                "name": "Bega, Australia",
                "latitude": -36.673919677734378,
                "longitude": 149.84178161621095,
                "showCustomizedDisplayName": false
            }
        ]
    }
}'

推荐阅读