表上的微数据

时间:2015-04-16 20:06:34

标签: 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>

请注意,streetAddressaddressCountry应该是address属性的子级。但是,您无法添加父div来对table中的内容进行分组。

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

如何支持这个?

1 个答案:

答案 0 :(得分:5)

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

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

<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>

您几乎可以使用itemref,因此您不必添加虚拟itemscope,但标记变得更复杂,您必须“外包”{{1 item:

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> 中的Person仍然有table,只需将其添加到第一个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>