dart - polymer :将内容嵌套在内容中

标签 dart polymer dart-polymer shadow-dom content-tag

<!-- my-poly -->
<template>
  <content select=".useBtn">
    <button id="defaultBtn">
      <content select=".useBtnIcon">
        Button
      </content>
    </button>
  </content>
</template>

因此,如果使用了我的Element,则用户可以输入一个按钮,而不是defaultBtn来显示。但是,如果未给出按钮,则将显示带有按钮文本的defaultBtn。但是,用户还应该可以选择使用defaultBtn并输入将在按钮中显示的文本或图标。

如果我使用<div class="useBtn"></div>,它将用作Button。但是<div class="useBtnIcon"> BtnText</div>似乎不起作用。有没有办法使这项工作?

最佳答案

根据规范,它不起作用。

http://www.w3.org/TR/shadow-dom/#content-insertion-points

The content element that satisfies all of the following conditions represents a content insertion point:

  • The root node of the content element is a shadow root
  • There is no other content element in the ancestors of the content element
  • There is no shadow element in the ancestors of the content element


考虑到这一点,我想您不能使此内容与嵌套的内容元素一起使用。

这将工作。如果同时应用了自定义图标,则将获胜
<polymer-element name="the-button">
    <template>

        <content id="contentButton" select=".useBtn">
            <button id="PREFIXEDdefaultBtn">
                Default Button
            </button>
        </content>

        <button id="defaultBtnWithCustomIcon">
            <!--be sure that this content element doesnt contain a default set -->
            <content id="contentIcon" select=".useBtnIcon"></content>
        </button>

    </template>

    <script>
        Polymer('the-button', {
            domReady: function () {
                var customIcon = this.$.contentIcon;

                var disNodes = customIcon.getDistributedNodes();
                //Test if the content element contains distributed nodes.
                if (disNodes.length !== 0) {
                    this.$.contentButton.remove();
                } else {
                    // the button is customized, remove the icon
                    this.$.defaultBtnWithCustomIcon.remove();
                }
            }
        });
    </script>
</polymer-element>

关于dart - polymer :将内容嵌套在内容中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27149961/

相关文章:

javascript - polymer 1.x : Obtaining customStyles property value

polymer - 对多个请求使用一个 iron-ajax 元素

dart-polymer - 如何更改飞镖的核心图标按钮和纸图标按钮的大小?

dart - 官方 Dart Polymer 示例未在 Chrome 中显示(在 IE 中工作)

dart - Uncaught TypeError:无法读取未定义的属性 'apply'-Dart Polymer

flutter - 如何使该折叠栏与我的Google map 一起显示?

flutter - Flutter:如何通过从值中搜索来从列表中获取索引?

api - 如何在Flutter中通过API发送数据?

flutter - 如何在 json 列表中为每个 map 显示单独的数据表和文本?

dart - 如何知道用户在 <paper-dialog> 上选择了哪个按钮?