JSS REST Dictionary Serviceによる辞書データのフェッチ

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

JSSアプリケーションからRESTディクショナリ サービスを呼び出すには、JSSRestDictionaryServiceを使用します。

メモ

この例では、プロジェクトの /srcディレクトリにファイルを作成し、/src/tempディレクトリにconfig.jsファイルまたはconfig.tsファイルがあることを前提としています。必要に応じてimportステートメントを調整し、プロジェクトの設定を反映させます。

JSS REST Dictionary Serviceを使用してディクショナリ・データを取得するには:

  1. 新しいdictionary-service.tsファイルで、RestDictionaryServiceクラスのインスタンスを作成し、設定オブジェクトを指定します。

    import { RestDictionaryService } from '@sitecore-jss/sitecore-jss';
    import config from 'temp/config';
    
    export const dictionaryService = new RestDictionaryService({
      apiHost: config.sitecoreApiHost,
      apiKey: config.sitecoreApiKey,
      siteName: config.jssAppName,
    });
  2. データを取得するファイルで、新しいディクショナリ サービス インスタンスをインポートして使用します。

    import { dictionaryService } from './dictionary-service';
    const language = 'en';
    dictionaryService.fetchDictionaryData(language).then(data => {
        // do something with the data
    });
この記事を改善するための提案がある場合は、 お知らせください!