列舉程式庫項目

透過列舉 Print Portal 程式庫取得根資料夾 ID 後,可以列舉特定根資料夾中的程式庫項目 (文件和子資料夾)。

關閉列舉程式庫項目

瀏覽器中的傳回頁面是列舉 Librarian 根資料夾項目的 JSON 格式內容。此範例中有三個物件。在本教學課程的後續步驟中,我們會列印 TLC39 Laser_53_rf.btw。

{

"library":{"id":"de6940a6-ff73-465b-aaf2-d39504420fa6",

"name":"Librarian",

"description":"Files that have been added to Librarian.",

"order":1,

"fileFilter":"*.btw",

"relativePath":"lib://","validVisibleUsers":[]},

"contents":["Document1.btw","BMW.btw","TLC39 Laser_53_rf.btw"]

}

關閉JavaScript 範例

複製
/*-----------------------------------------------------------------------------------
Display files from a root folder
*/
let basePrintPortalURL = "https://example.com/Bartender/";
let route = "libraries/";
let id = "9890beae-db51-4b74-a132-d6430a06a192"

fetch(basePrintPortalURL + route + id)
.then(response => response.json())
.then(result => {
  console.log(result);

  // The following will display a list of templates available in the specific library
  const fileList = result.contents;
  fileList.forEach(template => console.log(template));

  // Displays the name of the library
  console.log(result.name);

  // Displays the specific error message in case of a failed request
  console.log(result.errors.id);
  
  // Displays the title of the error message
  console.log(result.title);

  // Displays the error message status code
  console.log(result.status);

})
.catch(error => {
  console.error('There has been a problem with your fetch operation: ', error.message);
});