HTML5 Microdata – itemref到另一个itemscope(Person适用于Organization)

前端之家收集整理的这篇文章主要介绍了HTML5 Microdata – itemref到另一个itemscope(Person适用于Organization)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一个组织的网站,说“太阳工业”,想添加一个员工名单。该组织的地址和联系信息已经存在于网页上,但员工名单将在其他地方。

所以我们有

<div id="organization" itemscope itemtype="http://schema.org/Organization">
  <span itemprop="name">Sun Industries</span>,<span itemprop="location" itemscope itemtype="http://schema.org/Place">
    <span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
      <span itemprop="streetAddress">Technologies Street 42</span>,<span itemprop="addressLocality">Venustown</span>
      <span itemprop="postalCode">98765</span>
    </span>
  </span>
</div>

后来我们将会有HTML5代码

<div id="employee-1" itemscope itemtype="http://schema.org/Person">
  <span itemprop="name">John Doe</span>,<span itemprop="jobTitle">Sales Manager</span>
</div>

我们如何将两个对象“组织”和“员工1”联系在一起?

我尝试将以下小孩添加到“employee-1”对象中

<Meta itemprop="worksFor" itemscope itemtype="http://schema.org/Organization" itemref="organization">

但这并不奏效(至少不在Google的结构化数据测试工具中)。

在这种情况下,如何正确使用microdata属性itemref?

为了清楚,我也尝试了以下几点:

>将itemprop =“worksFor”添加到“组织”对象。
>将itemref =“organization”添加到“employee”对象。

所以

<div id="organization" itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">
  <span itemprop="name">Sun Industries</span>,...
</div>
...
<div id="employee-1" itemscope itemtype="http://schema.org/Person" itemref="organization">
  <span itemprop="name">John Doe</span>,<span itemprop="jobTitle">Sales Manager</span>
</div>

但是这给了我一个警告:页面包含属性“worksfor”,它不是模式的一部分。为“组织”对象。

解决方法

嗯,实际上你的最后一个代码片段看起来不错。
也许 Yandex Validator输出会更加清晰
person
  itemType = http://schema.org/Person
  worksfor
    organization
      itemType = http://schema.org/Organization
      name = Sun Industries
  name = John Doe
  jobtitle = Sales Manager

几个其他工作的例子。

<body>
  <div id="organization" itemscope itemtype="http://schema.org/Organization" itemref="employee-1">
    <span itemprop="name">Sun Industries</span>,<span itemprop="location" itemscope itemtype="http://schema.org/Place">
      <span itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
        <span itemprop="streetAddress">Technologies Street 42</span>,<span itemprop="addressLocality">Venustown</span>
        <span itemprop="postalCode">98765</span>
      </span>
    </span>
  </div>
  <div id="employee-1" itemprop="employee" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">John Doe</span>,<span itemprop="jobTitle">Sales Manager</span>
  </div>
</body>

给出以下内容

organization
  itemType = http://schema.org/Organization
  employee
    person
      itemType = http://schema.org/Person
      name = John Doe
      jobtitle = Sales Manager
  name = Sun Industries
  location
    place
      itemType = http://schema.org/Place
      address
        postaladdress
          itemType = http://schema.org/PostalAddress
          streetaddress = Technologies Street 42
          addresslocality = Venustown
          postalcode = 98765

或这个

<body>
  <div id="employee-1" itemscope itemtype="http://schema.org/Person">
    <span itemprop="name">John Doe</span>,<span itemprop="jobTitle">Sales Manager</span>
    <Meta itemprop="worksFor" itemscope itemtype="http://schema.org/Organization"  itemref="organization">
  </div>
  <div id="organization">
    <span itemprop="name">Sun Industries</span>,<span itemprop="addressLocality">Venustown</span>
        <span itemprop="postalCode">98765</span>
      </span>
    </span>
  </div>
</body>

结果

person
  itemType = http://schema.org/Person
  name = John Doe
  jobtitle = Sales Manager
  worksfor
    organization
    itemType = http://schema.org/Organization
    name = Sun Industries
    location
      place      
        itemType = http://schema.org/Place
        address
          postaladdress
            itemType = http://schema.org/PostalAddress
            streetaddress = Technologies Street 42
            addresslocality = Venustown
            postalcode = 98765

规范对于使用itemref并不是很清楚,但是例子有帮助

<div itemscope id="amanda" itemref="a b"></div>
<p id="a">Name: <span itemprop="name">Amanda</span></p>
<div id="b" itemprop="band" itemscope itemref="c"></div>
<div id="c">
 <p>Band: <span itemprop="name">Jazz Band</span></p>
 <p>Size: <span itemprop="size">12</span> players</p>
</div>

猜你在找的HTML5相关文章