在模板

问题描述

我有一个自定义元素“ thing-y”,该元素使用template和两个slot

      <template id="thingy-template">
          <details>
            <summary><slot name="thing-id">THING</slot></summary>
            <p><slot name="thing-content">VALUE</slot></p>
          </details>
      </template>

thing-y元素构造函数在阴影DOM中克隆模板

  customElements.define('thing-y',class extends HTMLElement {
    constructor() {
      super();
      const template = document
        .getElementById('thingy-template')
        .content;
      this.attachShadow({mode: 'open'})
        .appendChild(template.cloneNode(true));
    }
  });

然后在页面中的任意位置使用元素

      <thing-y id="something">
        <span slot="thing-id">Something</span>
        <span slot="thing-content">42</span>
      </thing-y>

到目前为止,很好。

现在,我想在slot的两个地方使用相同的template值,所以我将template的定义更改为

  <template id="thingy-template">
    <details>
      <summary><slot name="thing-id">THING</slot></summary>
      <p><slot name="thing-id">THING</slot> 
          content is <slot name="thing-content">VALUE</slot></p>
     </details>
  </template>

但是只有前slot内容被其值替换,第二个内容保持不变。

如何实现这个简单的要求?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...