我正在尝试创建一个自定义元素,在paper-dialog中播放youtube视频。因此,videoPlayer = Polymer.dom(this.root).querySelector('video-player');继承/访问了paper-dialog的open方法,我正在尝试扩展我的自定义元素。它不起作用,但希望我在正确的轨道上,有人可以正确地告诉我。
我使用的是Polymer 1.0,但是我只需要使用https://www.polymer-project.org/0.5/docs/polymer/polymer.html#extending-other-elements来扩展元素。
<link rel="import" href="../bower_components/paper-dialog/paper-dialog.html">
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
<link rel="import" href="../bower_components/google-youtube/google-youtube.html">
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="video-player">
<template>
<div class="layout horizontal">
<paper-button dialog-dismiss>
<paper-icon-button icon="arrow-back"></paper-icon-button>
</paper-button>
</div>
<div style="height: 100%; width: 100%">
<google-youtube style="height: 100%;"
video-id="YMWd7QnXY8E"
rel="1"
start="5"
playsinline="0"
controls="2"
showinfo="0"
width="100%"
height="100%"
autoplay="1">
</google-youtube>
</div>
</template>
<script>
Polymer({
is: "video-player"
});
</script><paper-dialog name="video-player" extends="video-player">
<template>
<shadow></shadow>
</template>
<script>
Polymer();
</script>
</paper-dialog><video-player></video-player>发布于 2016-01-16 22:41:22
正如注释中提到的那样,您还不能扩展自定义元素,因此现有的模式(至少是我使用的模式)是尽可能地使用行为,而包装则是在不使用的地方使用。
例如:
<dom-module id="popup-video-player">
<template>
<video-player></video-player>
</template>
<script>
Polymer({
is: 'popup-video-player',
behaviors: [Polymer.PaperDialogBehavior],
...
});
</script>
</dom-module>现在,您可以像使用<popup-video-player>一样使用paper-dialog。
我知道这很糟糕,因为如果video-player有很多您想要访问的属性,就必须将它们复制到popup-video-player元素的API中,这并不完全是干的。
如果你看一下 source,你会看到他们在做同样的事情。很明显,他们想要扩展iron-input,但是他们不能这样做:
<input is="iron-input" id="input"
aria-labelledby$="[[_ariaLabelledBy]]"
aria-describedby$="[[_ariaDescribedBy]]"
disabled$="[[disabled]]"
title$="[[title]]"
... >顺便提一句,您可以始终连接到<video-player>的“属性”属性,并通过编程方式添加API。
也许像这样的东西会起作用:(未经测试!)
Polymer({
...
properties: (function () {
var prop = {
//special properties specific to the pop up version of video-player
//..obviously be careful to avoid name space conflicts.
};
var video_player = document.createElement('video-player');
video_player.properties.keys().forEach( function(key) {
props[key] = video_player[key];
});
return props;
}()),
});https://stackoverflow.com/questions/31444119
复制相似问题