表上的微数据

fri*_*gon 7 html5 html-table microdata

我是Microdata的新手,并且在一个itemscope内部遇到问题table.

例如,假设我有一个人物对象,在表格中我显示了姓名,街道和城市列.

<table>
  <tr itemscope itemtype="http://schema.org/Person">
    <td itemprop="name">Name</td>
    <td itemprop="streetAddress">123 main</td>
    <td itemprop="addressCountry">USA</td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

请注意,streetAddress并且addressCountry应该是address属性的子项.但是你不能添加一个父div组来分组table.

此外,点符号似乎不起作用,例如address.streetAddress.

怎么会支持这个?

uno*_*nor 5

对此只有相当丑陋的解决方案.

您可以使用该itemref国家/地区的属性,但您必须添加一个虚拟无类型,itemscope以便该addressCountry属性不会添加到该Person项目:

<table>
  <tr itemscope itemtype="http://schema.org/Person">
    <td itemprop="name">
      Name
    </td>
    <td itemprop="address" itemscope itemtype="http://schema.org/PostalAddress" itemref="country">
      <span itemprop="streetAddress">123 main</span>
    </td>
    <td itemscope>
      <span itemprop="addressCountry" id="country">USA</span>
    </td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

itemref几乎可以使用任何东西,这样您就不必添加虚拟对象itemscope,但标记变得更复杂,并且您必须"外包"该Person项目:

<meta itemscope itemtype="http://schema.org/Person" itemref="person-name person-address" />

<!-- can’t have this as descendant of another Microdata item -->

<table>
  <tr>
    <td itemprop="name" id="person-name">
      Name
    </td>
    <td itemprop="address" itemscope itemtype="http://schema.org/PostalAddress" id="person-address" itemref="address-country">
      <span itemprop="streetAddress">123 main</span>
    </td>
    <td itemprop="addressCountry" id="address-country">
      USA
    </td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

或者还有Persontable将其添加到第一td:

<!-- can’t have this as descendant of another Microdata item -->

<table>
  <tr>
    <td itemscope itemtype="http://schema.org/Person" itemref="person-address">
      <span itemprop="name">Name</span>
    </td>
    <td itemprop="address" itemscope itemtype="http://schema.org/PostalAddress" id="person-address" itemref="address-country">
      <span itemprop="streetAddress">123 main</span>
    </td>
    <td itemprop="addressCountry" id="address-country">
      USA
    </td>
  </tr>
</table>
Run Code Online (Sandbox Code Playgroud)