具有FieldGeolocationValue的PnP JS添加项目-SharePoint

时间:2019-09-05 14:13:23

标签: javascript sharepoint sharepoint-online pnp-js

我正在尝试将一个项目添加到包含Geolocation字段的列表中,我在文档中找不到如何向该字段添加值的方法,我尝试了几种方法,但均未成功:

await web.lists.getByTitle('Opiniones')
.items.add({
   ...
   Location: { "__metadata": {"type": "SP.FieldGeolocationValue"}, Latitude: parseInt(req.body.lat||0), Longitude: parseInt(req.body.long||0) 
   ...
}

或这种方式:

await web.lists.getByTitle('Opiniones')
.items.add({
   ...
   Location: { Latitude: parseInt(req.body.lat||0), Longitude: parseInt(req.body.long||0) 
   ...
}

1 个答案:

答案 0 :(得分:1)

我已经测试过使用PnP Js设置位置字段值,并且可以正常工作:

  pnp.sp.web.lists.getByTitle("Products").items.add({
        Title: "NewLocationAdded",
        Location: {
          "__metadata": {"type": "SP.FieldGeolocationValue"},
          "Latitude": 60.2872339,
          "Longitude": 24.8516785
      }
    }).then(() => {
        console.log("done");
    });

enter image description here

enter image description here

在您这边,您可以像上面一样直接将“纬度和经度”设置为double值,以测试其是否有效。