我正在嘗試通過 Planner Graph API 設定任務的參考,但無法通過變數設定 URL。
我撰寫了一個單獨的方法來編碼 url,它回傳正確的值,但仍然沒有為 Planner 任務設定參考。
const updateAttachedFiles = (
links: string[],
taskId: string,
etag: string
) => {
var encodedLink: string;
links.forEach(async (link) => {
encodedLink = escapeHtml(link)
await graph.planner.tasks.getById(taskId).details.update(
{
references: {
encodedLink : {
"@odata.type": "microsoft.graph.plannerExternalReference",
"previewPriority": " !",
type: "Other",
},
},
},
etag);
}
)
};
const escapeHtml = (unsafe) => {
let temp = unsafe.replaceAll("%", "%")
unsafe = temp
.replaceAll(".", ".")
.replaceAll(":", ":")
.replaceAll("@", "@")
.replaceAll("#", "#");
return unsafe
}
但是,如果我將 encodingLink 更改為硬編碼的 URL(從變數 encodingLink 中設定的值復制),它就可以作業。
{
references: {
"https://shmafe.sharepoint.com/sites/PlannerTest1/Delade dokument/nedladdning.jpg" : {
"@odata.type": "microsoft.graph.plannerExternalReference",
"previewPriority": " !",
type: "Other",
},
},
}
我需要能夠動態設定鏈接,那么如何在不使用變數的情況下進行設定?我做錯了什么嗎?
更新 plannertaskdetails 的 Microsft 檔案 https://docs.microsoft.com/en-us/graph/api/plannertaskdetails-update?view=graph-rest-1.0&tabs=javascript
plannerExternalReferences 資源型別的 Microsft 檔案 https://docs.microsoft.com/en-us/graph/api/resources/plannerexternalreferences?view=graph-rest-1.0
uj5u.com熱心網友回復:
要將變數用作物件鍵,需要使用括號語法
例如:
const myVariable = 'hello';
const demoObject = {
[myVariable]: 'world'
};
console.log(demoObject[myVariable]);
// same as
console.log(demoObject.hello);
這應該解決它:
const updateAttachedFiles = (
links: string[],
taskId: string,
etag: string
) => {
var encodedLink: string;
links.forEach(async (link) => {
encodedLink = encodeURI(link)
await graph.planner.tasks.getById(taskId).details.update(
{
references: {
[encodedLink] : {
"@odata.type": "microsoft.graph.plannerExternalReference",
"previewPriority": " !",
type: "Other",
},
},
},
etag);
}
)
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/349979.html
標籤:javascript 打字稿 microsoft-graph-api microsoft-graph-plannertasks
上一篇:省略從不輸入打字稿
