当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。