有没有办法根据用户的国家/地区输出数组的特定部分?

is there a way to output specific part of array depending on the user's country?

我正在尝试根据用户的国家/地区代码获取 name: 和 value: 的值。所以示例用户位置是 'DE' 它应该输出:

TRS_TITLE_DE

Harry Potter Chamber Of Secrets I 硬壳后壳兼容 Apple iPhone12

这是数组:

{
          "id":3,
          "name":"TRS_TITLE_DE",
          "value":"Harry Potter Chamber Of Secrets I Hard Back Case Compatible With Apple iPhone 12"
       },
       {
          "id":4,
          "name":"TRS_TITLE_FR",
          "value":"Harry Potter Chamber Of Secrets I Hard Back Case Compatible With Apple iPhone 12"
       },
       {
          "id":5,
          "name":"TRS_TITLE_IT",
          "value":"Harry Potter Chamber Of Secrets I Hard Back Case Compatible With Apple iPhone 12"
       },
       {
          "id":6,
          "name":"TRS_TITLE_US",
          "value":"Harry Potter Chamber Of Secrets I Hard Back Case Compatible With Apple iPhone 12"
       },

这是我试过的:

{{#if settings.country_code "==" "DE"}}
  <h1>
    {{itemAt product.custom_fields 2}}    
  </h1>      
{{else}}
    <h1>It's not there</h1>
{{/if}}

假设您已将国家代码完全按照它们在设置中显示的那样放入自定义字段中,那么以下应该可以解决问题:

{{#each product.custom_fields}}
    {{#contains name ../settings.country_code}}
        <h1>{{{value}}}</h1>
    {{/contains}}
{{/each}}