表格上的微数据
Microdata on tables
我是 Microdata 的新手,在 table
中遇到 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>
请注意 streetAddress
和 addressCountry
应该是 address
属性 的子代。但是您不能添加父级 div
来对 table
.
中的那些进行分组
此外,点符号似乎不起作用,例如address.streetAddress
.
如何支持这一点?
对此只有相当丑陋的解决方案。
您可以使用国家/地区的 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>
您几乎可以将 itemref
用于任何内容,这样您就不必添加虚拟 itemscope
,但是标记变得更加复杂,您必须 "outsource" 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>
或者在 table
中仍然有 Person
,方法是将其添加到第一个 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>
我是 Microdata 的新手,在 table
中遇到 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>
请注意 streetAddress
和 addressCountry
应该是 address
属性 的子代。但是您不能添加父级 div
来对 table
.
此外,点符号似乎不起作用,例如address.streetAddress
.
如何支持这一点?
对此只有相当丑陋的解决方案。
您可以使用国家/地区的 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>
您几乎可以将 itemref
用于任何内容,这样您就不必添加虚拟 itemscope
,但是标记变得更加复杂,您必须 "outsource" 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>
或者在 table
中仍然有 Person
,方法是将其添加到第一个 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>