當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JavaScript ArcGIS PortalItem.addResource用法及代碼示例

基本信息

以下是所在類或對象的基本信息。

AMD: require(["esri/portal/PortalItem"], (PortalItem) => { /* code goes here */ });

ESM: import PortalItem from "@arcgis/core/portal/PortalItem";

類: esri/portal/PortalItem

繼承: PortalItem > Accessor

自從:用於 JavaScript 4.0 的 ArcGIS API

用法說明

PortalItem.addResource函數(或屬性)的定義如下:

addResource (resource, content, options) {Promise}


自從:ArcGIS 適用於 JavaScript 4.16 的 API

將新的 resource 添加到門戶項目。

參數:

規格:
類型說明

要添加到門戶項目的資源。

content Blob

資源內容。

options Object
可選的

具有以下屬性的對象。

規格:
access

String

可選的
默認值:"inherit"

指示對資源的訪問級別。默認值為"inherit",這會導致資源具有與擁有項目相同的訪問級別。

可能的值"inherit"|"private"

signal

AbortSignal

可選的

可用於中止異步任務的信號對象。當發出中止信號時,返回的 Promise 將被名為 AbortErrorError 拒絕。另請參閱AbortController,了解有關如何構建可用於傳遞中止信號的控製器的更多信息。

返回:

類型 說明
Promise 解決後,返回 PortalItemResource

例子:

// The following snippet assumes you have an existing portal item instance
// that you are allowed to modify

// An example of an object that we would like to store as a resource
const definition = { type: "world", description: "A world definition" };

const resource = new PortalItemResource({ path: "definitions/world.json" });

// Resource content is always passed as a blob. Define a blob that contains our definition
// in JSON encoding
const content = new Blob([JSON.stringify(definition)], { type: "application/json" });

portalItem.addResource(resource, content)
  .then(function () {
    console.log("Successfully added resource", resource.url);
  })
  .catch(function (error) {
    console.error("Failed to add resource", error);
  });

相關用法


注:本文由純淨天空篩選整理自arcgis.com大神的英文原創作品 PortalItem.addResource。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。