【问题标题】:How to find into array of hash where value is exist into array?如何找到值存在于数组中的哈希数组?
【发布时间】:2019-04-19 12:10:40
【问题描述】:

根据变体ID查找哈希

[
  {
    "id": 3693828997212,
    "position": 1,
    "created_at": "2018-07-17T03:25:44-06:00",
    "updated_at": "2018-07-17T03:25:48-06:00",
    "alt": null,
    "width": 273,
    "height": 320,
    "src": "https://cdn.shopify.com/s/files/1/1384/1935/products/HGPC4050B_aeb4f02b-64af-4e2b-8ded-60ddba027683.jpg?v=1531819548",
    "variant_ids": [
      12341420949596
    ],
    "admin_graphql_api_id": "gid://shopify/ProductImage/3693828997212"
  },
  {
    "id": 3693829455964,
    "position": 2,
    "created_at": "2018-07-17T03:25:46-06:00",
    "updated_at": "2018-07-17T03:25:48-06:00",
    "alt": null,
    "width": 273,
    "height": 320,
    "src": "https://cdn.shopify.com/s/files/1/1384/1935/products/HGPC8010B_ee78ecc9-22f1-41e6-899e-a425d7aef6e7.jpg?v=1531819548",
    "variant_ids": [
      12341420982364
    ],
    "admin_graphql_api_id": "gid://shopify/ProductImage/3693829455964"
  }
]

【问题讨论】:

    标签: ruby-on-rails ruby search


    【解决方案1】:

    我假设变体 ID 仅属于单个用户

    arr.find { |h| h[:variant_ids].include?(12341420982364) }
    

    【讨论】:

      猜你喜欢
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      • 2016-06-27
      • 1970-01-01
      相关资源
      最近更新 更多