在子模板中访问父模板的属性
Accessing properties of parent template in child template
我创建了一个具有嵌套模板的聚合物元素。我想在子模板中访问父模板的属性。
<dom-module id="gallery-content">
<template>
<template is="dom-bind">
<iron-ajax url="/getData" last-response={{data}} auto></iron-ajax>
<table id="table-stencils">
<tr>
<td>
<p>{{contentType}}</p>
<hr>
</td>
</tr>
<tr>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/11.jpg"></image-block>
</td>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/12.jpg"></image-block>
</td>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/13.jpg"></image-block>
</td>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/14.jpg"></image-block>
</td>
</tr>
</table>
</template>
</template>
<script>
Polymer({
is: "gallery-content",
properties:{
contentType: {
type:String,
value:"Others"
}
}
});
</script>
我无法访问父元素的 contentType
属性。
我在这个 gallery-content 元素中使用了另一个 polyment()。
这是您的 运行 plunkr 元素,没有 dom-bind
。请注意,我使用 json 作为 getData
服务和 image-block
的临时元素
我创建了一个具有嵌套模板的聚合物元素。我想在子模板中访问父模板的属性。
<dom-module id="gallery-content">
<template>
<template is="dom-bind">
<iron-ajax url="/getData" last-response={{data}} auto></iron-ajax>
<table id="table-stencils">
<tr>
<td>
<p>{{contentType}}</p>
<hr>
</td>
</tr>
<tr>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/11.jpg"></image-block>
</td>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/12.jpg"></image-block>
</td>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/13.jpg"></image-block>
</td>
<td>
<image-block description={{data.description}}
lastmodified={{data.lastModified}}
imagepath="../../images/14.jpg"></image-block>
</td>
</tr>
</table>
</template>
</template>
<script>
Polymer({
is: "gallery-content",
properties:{
contentType: {
type:String,
value:"Others"
}
}
});
</script>
我无法访问父元素的 contentType
属性。
我在这个 gallery-content 元素中使用了另一个 polyment()。
这是您的 运行 plunkr 元素,没有 dom-bind
。请注意,我使用 json 作为 getData
服务和 image-block