3

我想知道 shopify 模式上的嵌套块是否可能。我搜索它,但我找不到答案。如果有人知道该怎么做,请帮助我。

这是我的架构

"blocks": [
  {
    "type": "block_main",
    "name": "Block Main",
    "settings": [
      {
        "type": "text",
        "id": "block-name",
        "label": "Quote"
      },
      {
        "type": "url",
        "id": "block-link",
        "label": "URL"
      }
    ],
    "blocks": [
      {
        "type": "sub_block",
        "name": "Sub Block",
        "settings": [
          {
            "type": "text",
            "id": "sub-block-name",
            "label": "Quote"
          },
          {
            "type": "url",
            "id": "sub-block-link",
            "label": "URL"
          }
        ]
      }
    ]
  }
]
4

3 回答 3

5

不,这是不可能的。(很遗憾)

您将不得不使用不同的逻辑来创建嵌套块。

例如,您可以使用link_list字段并使用链接中的文本和 URL 来填充您正在查找的信息。

于 2017-12-14T07:06:12.657 回答
0

这样做(例如)

{
   "name": "FAQs",
   "settings": [
     {
       "id": "dev-faq-title",
       "type": "text",
       "label": "FAQ Title",
       "default": "Frequently Asked Questions"
     }
   ],
   "blocks":[
     {
       "type": "block-1",
       "name": "Block 1",
       "settings": [
         {
           "type": "text",
           "id": "title",
           "label": "Title"
         },
         {
           "type": "text",
           "id": "accordion-title",
           "label": "Accordion Title"
         }
       ]
     },
     {
       "type": "block-2",
       "name": "Block 2",
       "settings": [
         {
           "type": "text",
           "id": "title",
           "label": "Title"
         }
       ]
     },
     {
       "type": "block-3",
       "name": "Block 3",
       "settings": [
         {
           "type": "text",
           "id": "title",
           "label": "Title"
         }
       ]
     }
   ],
   "presets": [
   {
     "category": "Text",
     "name": "Top Bar"
   }
 ]

}

于 2020-03-28T10:11:19.607 回答
-6

我认为这只不过是一种表示数据通信的方式。为此,我总是创建一个关联数组,然后将其转换为 JSON。看看这个示例 PHP 代码

//创建关联数组

$data = array("blocks" => array("type" => "block_main", "name": "Block Main","settings" => array("0" => array("type" => "text", "id": "block-name", "label": "Quote"), [1] => array(type": "url", "id": "block-link", "label": "URL")), "blocks": "type": "sub_block", "name": "Sub Block", "settings": array("0" => array("type": "text", "id": "sub-block-name", "label": "Quote"), "1" => array(type": "url", id": "sub-block-link", "label": "URL"))))

//将数组编码为json

$json = json_decode($data)

当我们发送 Post 请求时,服务器端也会发生同样的情况。它还将嵌套的 JSON 请求呈现给关联数组,然后对数据做出反应。

于 2017-12-16T18:06:54.187 回答