最初的目的是为聚合物元素提供可配置的图像位置。看来我明白了一些错误,并没有把它做成“聚合物的方式”。问题在于如何实现这个目标,以及如果方法是正确的。v1.0元素中的聚合物元素访问属性
从调用页面:
<mycustom-element imagelocation="/correct/path/to/images"></mycustom-element>
和元素:
<link rel="import" href="proper/path/to/iron-image/iron-image.html">
<dom-module id="mycustom-element">
<style>
:host {
display: block;
}
</style>
<template>
<iron-flex-layout class="layout horizontal wrap top-level-menu">
<iron-image src="{{getLocation('image_file_name.png')}}"></iron-image>
</iron-flex-layout>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'mycustom-element',
properties: {
imagelocation: {
type: String,
value: "/wrong/path/to/images"
}
},
ready: function() {
console.info('RD', this.imagelocation);
},
getLocation: function(imageFilename) {
console.info('GLOC', this.imagelocation);
console.info('GLOC_PROP', this.properties.imagelocation.value);
return this.imagelocation + '/' + imageFilename.trim();
}
});
})();
</script>
,我有是在浏览器上查看时,的“this.imagelocation”的值是问题默认的一个,不是从调用页面提供的。
在控制台输出如下:
GLOC undefined
GLOC_prop /wrong/path/to/images
RD /correct/path/to/images
徘徊什么是错的?它是否与元素的生命周期有关?函数调用可以延迟吗?