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


JavaScript ArcGIS intl.SubstituteOptions用法及代碼示例

基本信息

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

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

ESM: import * as intl from "@arcgis/core/intl";

對象: esri/intl

自從:用於 JavaScript 4.12 的 ArcGIS API

用法說明

intl.SubstituteOptions函數(或屬性)的定義如下:

SubstituteOptions


指定替換選項的對象。

使用 format 屬性定義字符串模板中引用的每個值的格式。 format 是一個鍵值對對象。每個鍵可以是:

  • data 參數或 substitute() 的屬性
  • 可以在模板字符串中引用的命名格式化程序。

在以下示例中,data 中的 time 屬性將被格式化為日期,每個組件都采用數字格式。

const data = {
  time: Date.now()
};

intl.substitute("Date: {time}", data, {
  format: {
    time: {
      type: "date",
      intlOptions: {
        year: "numeric",
        month: "numeric",
        day: "numeric",
        hour: "numeric",
        minute: "numeric"
      }
    }
  }
});

以下示例使用命名格式化程序使用不同的格式化選項對 time 屬性進行兩次格式化。

const data = {
  time: Date.now()
};

intl.substitute("In {time:monthFormat} of {time:yearFormat}", data, {
  format: {
    monthFormat: {
      type: "date",
      intlOptions: {
        month: "long"
      }
    },
    yearFormat: {
      type: "date",
      intlOptions: {
        year: "numeric"
      }
    }
  }
});
屬性:
類型說明

格式化選項的字符串鍵的哈希映射。

相關用法


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